• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

PHP code guru please

Participant ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Hi guys,

I was just wondering if anyone would know how to do this, with PHP - I used to mess around with PHP  on an old site, but have forgotten most of it...   Here's what I need to do - I want to place the same internal link on several dozen different pages on my site (we might call these pages A1, A2, A3 etc), which will all direct the users to the same page (page 'B') - however when they arrive at page B, I need it to display an entire page of 'unique' product info, relevent only to the (various A1, A2, A3 etc) pages they clicked through from.   Hope that makes sense.

eg.  If page A1 was about apples, then once they clicked the internal link through to page B, they would see apples displayed, on page B.   But if they clicked through from page A2, which was about oranges - they would instead see oranges on page B.  

I know this is achievable, I just dont remember the code that is needed to do it.   Any thoughts, or even a link to a tutorial that will show me how to do this, would be much appreciated : )

Cheers,

Craig

 

TOPICS
Code , How to , Other

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 17, 2020 Feb 17, 2020

OK, simple as possible might be to name your include files simply for example like apples.php oranges.php plums.php

so you now redirect using a paramemter like Ben said, for example:

 

 

mypage.php?product=apples
mypage.php?product=oranges
mypage.php?product=plums

 

 

 

On you target page create a variable and create the include filename from the url paramter, like this (assuming it will always have a value):

 

 

 

<?php
$filename = $_GET['product'];
include $filename.".php";
?>

 

 

 

 

Votes

Translate

Translate
Community Expert ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Are you referring to URL parameters as in <a href="product.php?id=oranges>Go to oranges</a>

Wappler, the only real Dreamweaver alternative.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Hi Ben,
Thanks for your reply.  Yes, that is definitely half of the equation solved, thanks!     Then.. my issue would be getting oranges to only appear on page B when the reader has clicked through from the 'orange' page - this seems somewhat curlier.   ie. If I placed code something like this on Page B  <?php include("include/oranges.php"); ?>  it would display oranges to the apple readers (and all the other fruits ; ) as well - not sure how I can get it to discern the apple readers from the orange readers : )    Many thanks for your thoughts.

Cheers,

Craig

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Ideally you want your product information in a database, then you would create a query filtered by the URL parameter

Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

Ahhh, OK - thanks Paul.  Thats definitely getting way beyond my knowledge level, as I have only dealt with the 'include' folder for this stuff previously.   Good thought though, many thanks - it could certainly be outsourced if need be.

Cheers,

Craig  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2020 Feb 17, 2020

Copy link to clipboard

Copied

OK, simple as possible might be to name your include files simply for example like apples.php oranges.php plums.php

so you now redirect using a paramemter like Ben said, for example:

 

 

mypage.php?product=apples
mypage.php?product=oranges
mypage.php?product=plums

 

 

 

On you target page create a variable and create the include filename from the url paramter, like this (assuming it will always have a value):

 

 

 

<?php
$filename = $_GET['product'];
include $filename.".php";
?>

 

 

 

 

Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

yep you're right, except that personnaly I will do the opposite.

I mean instead of

 

1 -

calling a common page that call itself different appropriate content

A1 | A2 | An --> B and B --> orange | apple | pear and so on

 

I will

2 - call different page that call common content

A1 | A2 | An --> orange | apple | pear and all thoses call -->B

 

in fact how I see both method, the first one is database oriented, the second one is more flexible when using linked sheets, and so if datas have to be injected in different part of the page, i.e not only as an hero image.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Thanks Birnou, good to see there's multiple ways around it : )
Many thanks,

Craig T

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Thanks Paul, that's gold.   I can definitely play around with this and get the result I need, many thanks : )  

 

Cheers,

Craig T 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Thanks again guys.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2020 Feb 19, 2020

Copy link to clipboard

Copied

LATEST

You're welcome 🙂

Paul-M - Community Expert

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines