0

I currently have a search engine that links to my database and returns suggestions based on what you type (as long as it is longer than 2 characters). However, as it currently stands, the suggestions are simply text in a div. How can I make them able to be selected (by arrow keys and the mouse) and clickable so that they link to the respective search results page? k refers to search input. Thanks in advance.

<?php


if (isset ($_GET['k'])) {
    $k = $_GET['k'];

}
if (strlen($k) > 2) {
    if (!empty ($k)) {



        if (@mysql_connect('hostname', 'root', 'password')) {
            if (@mysql_select_db('search')) {

                $query = ("SELECT title FROM search WHERE title LIKE '%".mysql_real_escape_string($k)."%'");
                $query_run = mysql_query($query);

                while ($query_row = mysql_fetch_assoc($query_run)) {
                    echo $keywords = $query_row['title'].'<br>        <hr>';
                }
            }
        }


    }


}
?>
royce
  • 13
  • 2
  • What's wrong with echo'ing it as a link? `echo "$keywords";` – Fluffeh Jun 09 '14 at 01:24
  • Tips: According to [Here](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) mysql_real_escape_string isn't safe. I would recommand to you tu use [PDO](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – Orelsanpls Jun 09 '14 at 01:27

0 Answers0