Guest User

Untitled

a guest
May 7th, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Step 2.Make a PHP file to fetch and send results from database
  2.  
  3. We make a PHP file and save it with a name get_results.php
  4.  
  5. // Database Structure
  6. CREATE TABLE `search` (
  7. `title` text NOT NULL,
  8. `description` text NOT NULL,
  9. `link` text NOT NULL,
  10. FULLTEXT KEY ('title','description')
  11. ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
  12.  
  13. <?php
  14. if(isset($_POST['search']))
  15. {
  16. $host="localhost";
  17. $username="root";
  18. $password="";
  19. $databasename="sample";
  20. $connect=mysql_connect($host,$username,$password);
  21. $db=mysql_select_db($databasename);
  22.  
  23. $search_val=$_POST['search_term'];
  24.  
  25. $get_result = mysql_query("select * from search where MATCH(title,description) AGAINST('$search_val')");
  26. while($row=mysql_fetch_array($get_result))
  27. {
  28. echo "<li><a href='http://talkerscode.com/webtricks/".$row['link']."'><span class='title'>".$row['title']."</span><br><span class='desc'>".$row['description']."</span></a></li>";
  29. }
  30. exit();
  31. }
  32. ?>
  33.  
  34. In this step we create a database table called 'search' and enter some sample webpage details like title, description and link and we add fulltext key to title and description column because we only search in title and description text to find results.Then we get the search term and create a mysql query to get results we use fulltext searching to search in database.You can view our jQuery form validation tutorial to validate form.
Add Comment
Please, Sign In to add comment