简体   繁体   English

将SQL数据库查询结果显示为链接

[英]Display SQL database query result as link

I have a search form on a previous page where I allow users to search for $q. 我在上一页上有一个搜索表单,允许用户搜索$ q。 I then query the database for 'keys' LIKE $q. 然后,我在数据库中查询“键” LIKE $ q。 The while loop displays the 'name' and 'weblink' of each matching database entry. while循环显示每个匹配的数据库条目的“名称”和“网络链接”。

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'. 理想情况下,它看起来像是HTML:“ weblink”。 I cannot figure out the correct combo of php and html to make both the while loop, and the HTML work. 我无法弄清楚使while循环和HTML正常工作的php和html的正确组合。

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>';                           
    }  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM