Page 1 of 1

data retrieved from db with links

Posted: Sat Apr 19, 2008 9:44 am
by php_postgresql
i'm a newbie in php environment....

so i have retrieved my data from the database.. through an array...
i already retrieved it visually like in a webpage.... but.... i want to do something like (i dont know how to code it...i ran out of ideas...)
for example i have the data already...

1 cat black
2 dog white
3 pig flesh
4 sheep white



i want to put a link to each retrieved data in column 2.... (cat,dog,pig,sheep)
so that if i click the "cat" it will go to cat's profile....dog then dog's profile......

i dont really know how to do it cuz my resluts were from an array........
i hope someone can understand me.... thanks

Re: data retrieved from db with links

Posted: Sat Apr 19, 2008 9:56 am
by aceconcepts

Code: Select all

 
//query DB
 
while($row=mysql_fetch_array($query))
{
   echo'<a href="link.php?id='. $row['id'] .' ">'.$row['animal'] . ' - ' . $row['colour'] .'</a>';
}
 

Re: data retrieved from db with links

Posted: Sat Apr 19, 2008 10:00 am
by php_postgresql
wow thanks for the reply... i'll try it...but does this mean that the links to the profile must also be in the database?

and sir..can u pls exlpain this.... ---> a href="link.php?id
how will it know that it is pointing to the right profile..
thank u very much.....

Re: data retrieved from db with links

Posted: Sat Apr 19, 2008 10:15 am
by aceconcepts
link.php is the page that you're linking to (i don't know the page you're linking to so i just used link.php as an example)

?id is a varibable that will be passed via the address bar to link.php. id will retain the value of the id from the database (as specified in the code i posted in my first response).

From the page you link to (link.php) you can retrieve the profile id (?id=) like this:

Code: Select all

 
$id=$_REQUEST['id'];