Tuesday, 7 October 2014

Implementation of Live Search using Ajax,Jquery and PhP

<html>
<head>
<title>Search using Ajax</title>

 <script type=text/javascript src="https://code.jquery.com/jquery-git2.min.js">// necessary jquery source</script>
 <script>                                              //  Ajax jquery function for Live Search
        $(function(){
           $('.input').keyup(function(){
             var search = $('.input').val();
           
         $.post("s.php","post",{"search":search},function(data){
            $('.azam').html(data); 
            
          });
          });
          });
 </script>
</head>
 <body>
   <div class="azam">
  <form action=s.php method="post">
  <input type="text" name="search" class="input">
  <input type="submit" name="submit" value="search">
  </form>
 </div>
</body>
<?php
// Database Connection
mysql_connect("localhost","root","root");
mysql_select_db("Cake");
if($_POST['submit'])
{
//grab post data
$prod_form=$_POST['search'];


//extract data

$extract=mysql_query("SELECT username FROM users WHERE username LIKE '%$prod_form%'");


while($row=mysql_fetch_assoc($extract))
//displays the data of the database that satisfies 
{
echo "<br>";
echo $row['username'];
}

}   
?>


</html>