I am attempting to create an href link based on a MySQL query. I want to create a hyperlink that takes the user to the restaurant's page based on the results of their query. The following code shows hyperlinks to ALL of the restaurants. How do I modify it to show a single hyperlink based on a query? Thanks a lot!
Greg Gilbert
<?php
$db = mysql_connect("myip", "public", "public");
mysql_select_db("mydb",$db);
// display individual record
if ($id) {
$result = mysql_query("SELECT * FROM restaurants WHERE rest_id=$id",$db);
$myrow = mysql_fetch_array($result);
printf("Restaurant ID: %s\n<br>", $myrow["rest_id"]);
printf("Restaurant Name: %s\n<br>", $myrow["rest_name"]);
printf("Cuisine Code: %s\n<br>", $myrow["rest_cuisine"]);
printf("Delivery?: %s\n<br>", $myrow["rest_delivery"]);
printf("Catering?: %s\n<br>", $myrow["rest_catering"]);
} else {
$result = mysql_query("SELECT * FROM restaurants",$db);
if ($myrow = mysql_fetch_array($result)) {
// display list if there are records to display
do {
printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["rest_id"], $myrow["rest_name"], $myrow["rest_cuisine"]);
// printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", "restaurantpage.php", $myrow["rest_id"], $myrow["rest_name"], $myrow["rest_cuisine"]);
} while ($myrow = mysql_fetch_array($result));
} else {
// no records to display
echo "Sorry, no records were found!";
}
}
?>