Jump to content

capture a link to go back to the right page


dazzclub

Recommended Posts

He people,

 

A quick question,

 

i have a page that displays a product depending on which id is passed through the url.

 

lets call it display-product.php. Now there are several ways of getting to this page.

 

1) submitting a search and clicking on the retrieved result which then takes you to display-product.php

and

2)browsing through a product list and then click on a product for more information which then takes you to display-product.php

 

How can i create a link that goes back to the correct page??

 

kind regards

Dazzclub

  • 1 month later...

Hi, I thought I'd post back my findings.

 

What I opted to do after doing some research and with the help of you guys is to capture the id and then pass it through to the next page so the page can look at the id number and pull out the right one.

 

so in my case i had a navigation which where a list of links. These links, if pressed go to the products case studies, case_studies.php

 

case studies

------------------

Bud Exposed

Fosters Ice

Galliano

Guinness Pool

Heineken

Jersey Diary

Stella Artois

Diamond White

Metz

Tetley Tea

Tia Maria

Guinness Thirstmometer

Carling

 

 

The first thing i should mention is that the links above are all being pulled from my table in a database using this script;

<?php
				$casestudy = "SELECT * FROM casestudiesmenu";
				$result = mysqli_query($connection, $casestudy);

				While ($row = mysqli_fetch_array($result)){
				$case_name = $row["case_name"];
				$title = $row["title"];
				$id=$row["id"];


			 echo '
			<li><a href="case-studies.php?ID=' .$row["id"]. '" title="'. $row["title"].'" class="class4" >' . $row["case_name"]. '</a></li>';

		}
		?>

Now when i hover a link it displays, case-studies.php?ID=

 

Now i need script that will capture the id and then retrieve the correct case study accordingly, and for this i will place the script in the case-studies.php and the script looks like this;

 

if ( (isset($_GET['ID'])) && (is_numeric($_GET['ID'])) ) { //correctly accessed 
$id=$_GET['ID']; 
} else { 
$errors[] = 'You have accessed this page incorrectly.'; 
} 


{
	$sql = "SELECT * FROM case_studies WHERE ID = $id";

	If ($r = mysqli_query ($connection, $sql)) { 
	//sending the query to the mySQL server
	While ($row = mysqli_fetch_array($r)) { 
	//inputs the data into the table


	$id = $row['ID'];
	$case_title = $row['case_title'];
	$content = $row['content'];
	$download = $row['download'];
	$image = $row['image'];
	}
}
}	
?>
[code/]
This isnt meant to be a tutorial at all , i just wanted to show you guys how i had accomplished this task and if it helps anyone then thats even better eh.

again thanks to everyone in this forum for their patience and help.

kind regards
Dazzclub

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.