how can i add auto suggestion to my php mysql search engine? -


i'm trying create php mysql search engine working e-comerce search engine auto suggestion using ajax?... table like

id    cat    name    1    men    subi  2    men    flick  3    women  sheeba  4    women  leena 

my form

<html> <head> <title>search engine</title> </head> <body> <form action = 'ss.php' method ='get'> <input type = "text"  name = "q"> <input type = "submit" name = "submit" value = "search" </body> </html> 

and ss.php is

$k = $_get["q"]; $con = mysqli_connect("localhost", "root", ""); mysqli_select_db($con,"x"); $terms=explode(" ",$k); $i=0; $set_limit = ("9"); $subi = ""; foreach ($terms $each)   { $i++; $escapedsearchstring = mysqli_real_escape_string($con,$each); if ($i == 1 )     $subi.= " title '%$escapedsearchstring%' "; else     $subi.= " , title '%$escapedsearchstring%' ";  }  $query = "select sql_calc_found_rows * table $subi order       rand() limit $set_limit";  $qry = mysqli_query($con,"$query");  $row_object = mysqli_query($con,"select found_rows() rowcount"); $row_object = mysqli_fetch_object($row_object); $actual_row_count = $row_object->rowcount; $result = $actual_row_count; 

it's work fine when search words subi or sheeba bt want if i'm start type word 's' 'll shows auto suggestion like

sheeba subi sheeba in women subi in men 

if user clicks sheeba query automaticaly changed

" select * table title '%sheeba%' " 

and if user clicks 'sheeba in women' 'll query changed

" select * table cat = 'women' , title '%sheeba%' " 

how can obtain this? pls answer briefly... tnx in advance....

if want create custom code rather using plugin need

     $(document).ready(function() {         $("input[name='q']").on("keyup",function(event){             search_value = $(this).val();             // check whether input not empty or has characters             if(value.length > 0){                 $.ajax({                     url: '/path/to/file',                     type: 'get',                     datatype: 'json',                     data: "q="+search_value,                     success: function(response){                         // create suitable html body show reponse                          $("suggestion_box_id").html("your/created/htmlcontent");                     }                 })              }             else {                 $("suggestion_box_id").html("");             }         })     }); 

Comments