Display SQL database query result as link
I have a search form on a previous page where I allow users to search for $q. I then query the database for 'keys' LIKE $q. The while loop displays the 'name' and 'weblink' of each matching database entry.
This all works correctly. However, I would like the 'weblink' to display as a clickable link. Ideally it would read as if it were HTML: 'weblink'. I cannot figure out the correct combo of php and html to make both the while loop, and the HTML work.
Any help would be appreciated. Thanks in advance.
// query database
$query = mysql_query("SELECT * FROM `forumlist` WHERE `keys` LIKE开发者_开发问答 '%$q%'");
// display query results
while($row = mysql_fetch_array($query))
{
echo $row['name'];
echo "<br/>";
echo $row['weblink'];
}
while($row = mysql_fetch_array($query))
{
echo $row['name'];
echo "<br/>";
echo '<a href="' . $row['weblink'] . '">' . $row['weblink'] . '</a>';
}
精彩评论