How to Create Search Query using PHP/MySQL
Submitted by alpha_luna on Saturday, June 18, 2016 - 10:13.
In this tutorial, we are going to create Search Query using PHP/MySQL. Search query using PHP/MySQL is a simple PHP source code that the users enable to search in the table.
Creating one TextBox for the user where they enter the desired word to search and the table with our data in a data table as you can see in the image below.
Here's the source code of the image above. Kindly copy and paste to your BODY tag of your page.
We are going to search the "Programming" word. Let's enter to the TextBox and it will show in the image below what happen next.
As you can see in the image above, only has a Programming word display on our table.
Here's the source code for the searching data in our data table.
Hope that this tutorial will help you a lot.
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

- <div class="row-fluid">
- <div class="span6">
- <div class="span6">
- <form method="POST" action="search.php" class="navbar-search pull-left">
- <input type="text" name="search" class="search-query" placeholder="Search">
- </form>
- </div>
- <br />
- <br />
- <br />
- <table class="table table-bordered table-hover table-striped">
- <thead>
- <tr>
- </tr>
- </thead>
- <tbody>
- <?php
- $query = mysql_query("select * from book") or die(mysql_error());
- while ($row = mysql_fetch_array($query))
- {
- ?>
- <tr>
- <td><?php
- echo $row['title']; ?></td>
- <td><?php
- echo $row['author']; ?></td>
- <td><?php
- echo $row['category']; ?></td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>

- <div class="span12">
- <br />
- <br />
- <br />
- <div class="row-fluid">
- <div class="span6">
- <div class="span6">
- <form method="POST" class="navbar-search pull-left">
- <input type="text" name="search" class="search-query" placeholder="Search">
- </form>
- </div>
- <br />
- <br />
- <br />
- <table class="table table-bordered table-hover table-striped">
- <thead>
- <tr>
- </tr>
- </thead>
- <tbody>
- <?php
- if (isset($_POST['search']))
- {
- $search = $_POST['search'];
- $query = mysql_query("select * from book where category like '%$search%' or title like '%$search%' or author like '%$search%'") or die(mysql_error());
- while ($row = mysql_fetch_array($query))
- {
- ?>
- <tr>
- <td><?php
- echo $row['title']; ?></td>
- <td><?php
- echo $row['author']; ?></td>
- <td><?php
- echo $row['category']; ?></td>
- </tr>
- <?php
- }
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
- </div>
Add new comment
- 3110 views