Friday, 16 September 2016

How To Make Search Query with PHP and Mysql: Serach query simple Programme

This code explains how to make Search engine using php and my sql.
create table with name of sites.create input tag with the name of "value". Then in the PHP code get the value coming from the input tag. Search in the database if there is any word related to that query using "like "  keyword. No matter how many values you are provided. After searching the Keywords we have to displays it with three line as google in this example,first tittle follwed by link and description those columns should be added in the "sites" table.



To make search query just write as follows:



<html>
     <head>
     </head>
     <body>
              <FORM action="search.php" method="post">
                   search engine:<input type="text" name="value">
                   <input   type="submit" name="search" value="search now">
             </FORM>
        <hr>
       
 <?php
             mysql_connect("localhost","root","");
             mysql_select_db("mini_project");
   
                 if(isset($_POST['search']))

                  {
                         $search_value=$_POST['value'];
       
                          $query = "select * from sites where site_keywords like '%$search_value%'";
                         $run = mysql_query($query);
       
                          while($row=mysql_fetch_array($run))

                               {
                                     $tittle = $row['site_tittle'];
                                    $link = $row['site_link'];
                                    $desc = $row['site_desc'];
           
                                 echo "<h1>$tittle</h1><a href='$link'>$link</a><p>$desc</p>";
           
                               }
       
                  }
 ?>
    </body>
</html>

No comments:

Post a Comment