How to create own search engine using PHP, jQuery and MySQL
In this article, we will talk about creating our own search engine with the help of PHP and MySQL. Our goal is not to replace the big giants e.g. Google, Yahoo etc but to give a good attempt in order to have our own search engine. In this article we will talk about the basics of search engine and then see how to develop our own search engine using PHP and MySQL. You may also like Live Search in php with Ajax and Mysql and How to Autocomplete Textbox Using jQuery,PHP and MySQL.
HTML & jQuery Code
<html>
<head>
<script type="text/javascript">
function search()
{
var search_term = $("#search_term").val();
$.ajax
({
type: 'post',
url: 'get_search.php',
data: {
search: "search",
search_term: search_term
},
success: function (response)
{
$('#result_div').html(response);
}
});
return false;
}
</script>
</head>
<body>
<form method="post"action="get_results.php" onsubmit="return search();">
<input type="text" id="search_term" name="search_term" placeholder="Enter Search" onkeyup="search();">
<input type="submit" name="search" value="SEARCH">
</form>
<div id="result_div"></div>
</body>
</html>
PHP Code (get_search.php)
<?php
if(isset($_POST['search']))
{
$search_val = $_POST['search_term'];
$get_result = mysqli_query($con,"select * from search where MATCH(title,description) AGAINST('$search_val')");
while($row = mysqli_fetch_assoc($get_result))
{
echo "<li><a href='https://scripts.guru/".$row['link']."'><span class='title'>".$row['title']."</span><br><span class='desc'>".$row['description']."</span></a></li>";
}
}
?>
Leave a Reply