Jump to content

Database querying and using hyperlinks with the data


soullessj

Recommended Posts

Hi

 

I'm wondering if it is possible to query a database for info and then when i get the info such as 'Name' to be able to turn the list of names into a corresponding hyperlink.

 

ie.

 

name 1

name 2

name 3

name 4

name 5

 

if i were to click name 1 it would send me to a page setup to display name 1 information and if i clicked name 2 it would do the same but show me name 2 information.

 

At the moment i am manually creating the name and hyperlinking it to another page using the $id variable to be carried over into the page and select the info that i want to display from the database.

 

Thanks

 

 

you would query the database and then run a while loop to setup your links

 

<?php
$sql=mysql_query("SELECT * FROM table");
while ($result=mysql_fetch_array($sql)) {
$id=$result['id'];
$name=$result['name'];
echo "<a href=\"http://www.somesite.com/somepage.php?id=$id\">$name</a><br/>";
}
?>

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.