2

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

1 Answer 1

5
while($row = mysql_fetch_array($query))
    {
        echo $row['name'];
        echo "<br/>";
        echo '<a href="' . $row['weblink'] . '">' . $row['weblink'] . '</a>';                           
    }  
Sign up to request clarification or add additional context in comments.

4 Comments

@SeanA Why would I want to do that?
That was easier than I thought. Works perfect. Thanks!
@alex Oops, yeah, you are right. I just meant if weblink happened to have a double quote in it, it would break the HTML, so you may need to handle that, especially if weblink is user input.
@SeanA If it were user input, I would echo with htmlspecialchars().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.