Php MySQL

How to make multi property Search bar by php

add a multi property Search bar in your website by php

When a website holds excessive data, we can not show the entire data on one page, so we need the search bar. So in this post we will create a search bar. This will create two types of search times, the first will be the basic search bar, which will teach the Beginners, and the second advance will be the search bar in which we will target more than one property. You will learn to create both basic and advanced search bars, if you are new to our website, then check out our old posts where we have put many posts related to the database management system, introduction of basic php, and XAMPP server. Here we will first learn how to create basic search bar, then you will learn to create advanced search bar.

 

You must have basic knowledge of php before creating a search bar, without php you can not create search bar. In addition to php, you should also have a lot of knowledge about HTML and CSS. If you know all this, then there will also be some need for some software like XAMPP, Notepad, etc.

STEP[1]. Create a database as “project_1” and make a database table like this

Create a Database table and give it name”data_table
id   int 11  A.I.
name   text 50  –
village   text 50  –
district   text 50  –

 

STEP[2]. Here , i make a new page for placeing search bar, you add it in your page where you want.

<!—Database connection—>
<?php $con = mysqli_connect(“localhost”,”root”,””,”project_1″); ?>
<!—HTML CODE—>
<form method=”get” action=”result.php” enctype=”multipart/form-data”>
<input type=”text”name=”item”placeholder=”Search…..”>
<input type=”submit”value=”Search”name=”search”>
</form>

 

 

STEP[3]. Here, i making a page for showing Search Results

<!—Database connection—>
<?php $con = mysqli_connect(“localhost”,”root”,””,”project_1″); ?>
<!—HTML CODE—>
<form method=”get” action=”result.php” enctype=”multipart/form-data”>
<input type=”text”name=”item”placeholder=”Search…..”>
<input type=”submit”value=”Search”name=”search”>
</form>
<!—PHP SCRIPT—>
<table border=’1′ cellpadding=’1′ cellspacing=’1′ style=’width:500px’>
<tbody>
<tr>
<td>Id</td>
<td>Name</td>
<td>Village</td>
<td>District</td>
</tr>
<?php
if(isset($_GET[‘search’])){
$user_keyword=$_GET[‘item’];
$get_item=”select * from data_table where name like’%$user_keyword%’|| village like’%$user_keyword%’||district like’%$user_keyword%'”;
$run_item=mysqli_query($con, $get_item);
$count= mysqli_num_rows($run_item);
if($count==0){
echo”<h2 align=’center’ style=’font-size:30px;padding:100px’>Nothing Found There</h2>”;
}
while ($row_table=mysqli_fetch_array($run_item)){
$id = $row_table[‘id’];
$name = $row_table[‘name’];
$village = $row_table[‘village’];
$district = $row_table[‘district’]; echo”
<tr>
<td>$id</td>
<td>$name</td>
<td>$village</td>
<td>$district</td>
</tr>
“;
} } ?>
</tbody>
</table>

STEP[4]. Let’s test it, add some values into database table , and Search them.

 

 

Advance Search Bar & Multi Property Search Bar Coming Soon…

We hope that through this post you will also experience the ease of creating a search bar in your website, if you have any suggestions or problems can comment.

 

Kamal

My name is Kamalesh saini , working as e-mitra operator and web developer too. i am here to guide people who need help in learning php MySQL, HTML,CSS, and javascript.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.