Search functionality in dynamic website using php, MySQL

Welcome Readers, search functionality is the basic and main function that every website must have. Every website provides that functionality for user convenience in accessing the website. Now, we’re also going to learn how to include it in our site.

Creating Database

So, we first need to create a table in a Database to have some data and we will then try to find it. run the following SQL query to create the table. The table contains id, name, email and company name as the columns.

Now, add some rows in table as follows.

Creating front UI

Now our database is ready. we’ll now create an html page where we can display a text box and put the string to find. Lets create file database-search-form.html with following code. It simply provides the front end UI.

We’ve provided the UI using css. You can get it by downloading the source code below.
Go to above created file. You will get the following screen.

Search functionality in dynamic website using php, MySQL

The button will not work for now because we’ve not attached the back end. proceed further to add it.

Adding Search Functionality

Create file php-database-search.php and put following piece of code in it. It will act as a back end engine for our project.

That’s it! You are now good to go. Now, try to find by entering the employee name or company name. The matching results will be shown in table.
Search functionality in dynamic website using php, MySQL

If you have any doubts, feel free to ask them in comment box below. You can download the source code directly from the following link.

Download Source Code

5 thoughts on “Search functionality in dynamic website using php, MySQL

  1. P
    Peter says:

    Hi, how do I have to change the code if I want to implement 2 searches on one site. Both are looking on different tables.
    Second question: is it possible to search in two tables?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.