PHP linking dependant on mysql query?

Associate
Joined
1 Oct 2004
Posts
793
Location
Windsor
Is it possible for PHP to create a link dependant on what appears in a mysql query?

I have a search on my website which querys the database dependant on a search term and gives a result. e.g. a search result of cats creates a link which will take you to cats.html.

Currently I have this code in my search engine php:

Code:
echo '- <a href="xxxxxxx">'. $row['name'] . ' ' . $row['catagory'] .'</a>;

This makes whats displayed (name & catagory) a hyperlink but how do I make my link dependant on whats displayed in catagory so once clicked on it takes the user to that page?

Cheers guys.
 
Change xxxxxxxx to $row['catagory'] [sic] - easy :D

Edit: Well, you probably want more than that I guess. Assuming you have one page which displays info from a cateogry, let's call it display.php, you can pass parameters through the URL - the question-mark thing (like how these forums work, see the address bar). This is called the 'GET' method.

You can pass a variable and its value in the form:

display.php?variable=value

So - since it's a category, we'll call the variable category, as this makes sense to us humans. And the value will be the text from the database row:

display.php?category=home
display.php?category=work

And so on.

So just edit xxxxxx to include:

Code:
'?category='.$row['category']
 
Last edited:
Back
Top Bottom