Jump to content

How To Record "id's" In Link


Hemlock

Recommended Posts

I was wondering, I want to make a set of links on my page, which basically hold a value (number in this case), which I want to if clicked to be presented on the second page which the links are all directed to.so far I have the following

	<?php 	for ($i=0; $i<3; $i++)		echo "<a href='page2.php' name='link'>Clickable Link</a>" . "<br />";	?>

this makes the links for me, but I really have no clue how I would go about attaching a number that I want to display on the second page goes.

Link to comment
Share on other sites

I was wondering, I want to make a set of links on my page, which basically hold a value (number in this case), which I want to if clicked to be presented on the second page which the links are all directed to.so far I have the following
	<?php 	for ($i=0; $i<3; $i++)		echo "<a href='page2.php' name='link'>Clickable Link</a>" . "<br />";	?>

this makes the links for me, but I really have no clue how I would go about attaching a number that I want to display on the second page goes.

You just need to put the variable in the string you're outputting:
for ($i=0; $i<3; $i++) {  echo "<a href='page{$i}.php' name='link'>Clickable Link</a>" . "<br />";}

Link to comment
Share on other sites

You have to add the number to the query string of the URL. In the other page, you access the number with the $_GET array:First page:

for ($i=0; $i<3; $i++) {  echo "<a href='page2.php?id={$i}' name='link'>Clickable Link</a>" . "<br />";}

page2.php:

if(isset($_GET['id'])) {  echo $_GET['id'];}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...