data retrieved from db with links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_postgresql
Forum Newbie
Posts: 13
Joined: Sat Apr 19, 2008 9:37 am

data retrieved from db with links

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: data retrieved from db with links

Post 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>';
}
 
php_postgresql
Forum Newbie
Posts: 13
Joined: Sat Apr 19, 2008 9:37 am

Re: data retrieved from db with links

Post 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.....
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: data retrieved from db with links

Post 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'];
 
Post Reply