Dan Hoerst
Dan Hoerst

Reputation: 6328

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

Upvotes: 2

Views: 7345

Answers (1)

alex
alex

Reputation: 490657

while($row = mysql_fetch_array($query))
    {
        echo $row['name'];
        echo "<br/>";
        echo '<a href="' . $row['weblink'] . '">' . $row['weblink'] . '</a>';                           
    }  

Upvotes: 5

Related Questions