Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Step 2.Make a PHP file to fetch and send results from database
- We make a PHP file and save it with a name get_results.php
- // Database Structure
- CREATE TABLE `search` (
- `title` text NOT NULL,
- `description` text NOT NULL,
- `link` text NOT NULL,
- FULLTEXT KEY ('title','description')
- ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
- <?php
- if(isset($_POST['search']))
- {
- $host="localhost";
- $username="root";
- $password="";
- $databasename="sample";
- $connect=mysql_connect($host,$username,$password);
- $db=mysql_select_db($databasename);
- $search_val=$_POST['search_term'];
- $get_result = mysql_query("select * from search where MATCH(title,description) AGAINST('$search_val')");
- while($row=mysql_fetch_array($get_result))
- {
- 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>";
- }
- exit();
- }
- ?>
- 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