check this code .i think it will help you
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP, jQuery search demo</title>
<link rel="stylesheet" type="text/css" href="https://stackoverflow.com/questions/42627922/my.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input").keyup(function () {
$('#results').html('');
var searchString = $("#search_box").val();
var data="search_text=" + searchString;
if (searchString) {
$.ajax({
type: "POST",
url: 'search.php',
data: data,
dataType: 'text',
async: false,
cache: false,
success: function (result) {
$('#results').html(result);
//window.location.reload();
}
});
}
});
});
</script>
</head>
<body>
<div id="container">
<div style="margin:20px auto; text-align: center;">
<form method="post" action="do_search.php">
<input type="text" name="search" id="search_box" class="search_box"/>
<input type="submit" value="Search" class="search_button"/><br/>
</form>
</div>
<div>
<div id="searchresults">Search results :</div>
<ul id="results" class="update">
</ul>
</div>
</div>
</body>
</html>
first create html and jquery code for input field which you type
then call jquery function keyup which hit database using ajax method
then create a php file which manage your search i create a search.php file
<?php
$servername = "localhost";
$username = "db_username";
$password = "db_password";
$dbname = "your_db_name";
$searchquery = trim($_POST['search_text']); //input for search
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT filed1, field2 FROM yourtable_name WHERE match_text LIKE '%$searchquery%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo " - Name: " . $row["filed1"]. " " . $row["field2"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
from this page you will get your search result and you can change it as your demand . for your check you can also add search text length if you do not search if search text length > 2 or etc
0
solved How to Search value from input by mysqli in database