using variable within a hyperlink

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
billabon0202
Forum Newbie
Posts: 8
Joined: Wed Feb 20, 2008 11:31 am

using variable within a hyperlink

Post by billabon0202 »

First is this possible. I want to use a variable that i pulled from an array within my hyperlink. \

Ex. I pulled the foodtype variable from my database using:

$qry= "SELECT DISTINCT (restaurant_info.food_type) as foodtype
FROM restaurant_info
INNER JOIN restaurants
ON restaurants.rest_id= restaurant_info.rest_id
WHERE restaurants.delivery = 'yes'
ORDER BY food_type ASC";

Then i wanted to use that data to echo hyperlink created by that variable (foodtype)

$result = mysql_query($qry); //result of the query

if (!$result) {die(mysql_error()); //if result is empty then show error and stop process
}else{
echo '<ul>'; //start unordered list for links
while($row = mysql_fetch_array($result)) {

// CREATE link using $row['foodype'].html
this is where i am confused
echo '<p><li><a href=" ' $row[foodtype] ' . '.html' " >' . $row['foodtype'] . '</a></p>';

}
echo '</ul>';
}

And second, what is the syntax for doing something like that, i have tried to search for it but have been unsuccessful.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: using variable within a hyperlink

Post by Zoxive »

Code: Select all

echo '<p><li><a href=" ' $row[foodtype] ' . '.html' " >' . $row['foodtype'] . '</a></p>';// Notice how it looks with highlighting
=>

Code: Select all

echo '<p><li><a href="' . $row['foodtype'] . '.html" >' . $row['foodtype'] . '</a></p>'; 
 
||

Code: Select all

echo "<p><li><a href=\"{$row['foodtype']}.html\">{$row['foodtype']}</a></p>";
 
Last edited by Zoxive on Wed Feb 20, 2008 5:23 pm, edited 1 time in total.
billabon0202
Forum Newbie
Posts: 8
Joined: Wed Feb 20, 2008 11:31 am

Re: using variable within a hyperlink

Post by billabon0202 »

that doesnt work either, how do i fix the syntax
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: using variable within a hyperlink

Post by John Cartwright »

Those will work fine. What exactly did you try and what is the output?
Post Reply