How to make Search box & filter data in HTML Table from Database in PHP MySQL | PHP Tutorials - 15

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back so guys in this video we are going to learn about how to make a search box and filter those data in html table format so guys now let's see a demo so over here let me just search one data called ve and you can see that one record has come let me search with only first letter v so you can see all data has come let's search with the a where you can see many data so this is how we are going to make a search box option so let's let's get started so first let's move so guys here is the user interface where i'm using bootstrap 5 to design this form and now guys let's get started with it so first we need to create one row with column md7 and now we need to create that search box so let us go to bootstrap over here and type input group let's see we can take this design so let's just copy this design from here copy and paste inside this form and now guys we need to remove some things which we don't required over here let's remove and you can tell this as search data and then name is equal to where you are going to tell search and value is equal to right now we'll keep null and one simple form we are going to cut this and paste below this that's it and now let's give the method one submit button so let's remove this and create one simple button search type is equal to submit and one class button button hyphen primary save and now let's see the output guys for this get back let me just close this okay so here is the search button so when we click on this data should get searched so guys you can see that search value has come i mean parameters in your url so let's set with over here the value has come with that okay so let's fetch this value into your input box first let's get back let's open php and close php and type if condition inside that is set function to check the url is set or not i mean parameter is set or not so for that let's copy that and paste over here so this search is nothing but your parameters which we have sent over here we are checking that if it is set you need to echo that so let's give echo dollar underscore get method get method is a method to get all the data from your url so let's paste again and now guys let us refresh and check so you can see correct value has come so let me just type a over here you can see a is there and a also present so let's now let's fetch the data according to this whatever we search on this the data should fetch and show so what we are going to fetch is nothing but our user table this is my user table inside my php tutorials we have created one user table inside that all fields of user data is there so now let's fetch this according to this search so let's get back and get started as simple there's my row ends and row columns over here so let's begin with that creating one simple table format to view the output let's design one card where margin top four card body and inside this card body you are going to design the table table bordered let's give table head table row and this table heading where i want only id the first name the last name and final email that's it so let's fetch this into a table data i mean table body tr and inside this td tag we are going to fetch all the details over here so before that you need to code over here so let me just show you output of this refresh you can see that table structure is ready so whenever we search the data that table data should filter over here let's get let's start with the php coding open first we need to create a database connection mysql i underscore connect function where you have to give first localhost the username that is root password is null and the database name is php tutorial so let me just copy this and paste done and now guys let's write the query so before writing query we need to check that if it is searched or not this input field so if it is searched anything over here that time only it should come right it is set mean so let's copy this search and use if condition to check that let's use a set function to check whether it is set or not so if it is set then only you have to come inside this so now let's tell over here as dollar filter values where you are going to store all the searched items or values so this search values you are going to store over here and now let's write a query for it so dollar query is equal to where you are going to type select all the details from which table user table so let's copy the table name user paste and now you list where condition where and one more condition you are going to use that is concat let's use con cat and inside this you are going to search what the fields you want to search like i want to search the first name last name and email i want these three records to be searched and fetch the data into that so let's type this first name last name and email first t let's make it in lowercase first name comma last name comma email so i want these three fields to be searched when i'm searching that using like a like condition and inside the single quotes you have to give percentage double percentage inside that and then pass this your variable called filter values let's copy that and pass inside this save so we have missed one spelling mistake over here write first name so make sure your column names are correct over here and now let's execute this above statement so let's copy and paste an underscore run where you are going to run this with the mysqli query function so first your database connection and then your statement that is nothing but your query that query and now guys we will check that if there is data or not inside this query run with the help of mysqli number of rows function you are going to check over here if it is greater than zero then you have to come inside this else you need to tell that no record font so let's divide this php and paste this code inside this let's just arrange with it and now you can tell inside this no record found where i'm going to all call span is equal to which will be one two three four records i mean four columns of your table where we will add four save this and now guys same way you are going to fetch inside this let's use for each not for it for each loop to filter the records let's get this as dollar items so let's echo this item so we will use the html table structure to view that output so let's divide this php and again copy this same thing and paste and now let's remove this and type your php open is equal to where this is equal to is for echoing the data so what you are going to echo first you will echo id and then again the first name of your column first name and the last name last name and finally email let's save and now let us see the output guys let's get back search over here you can see no record found on this data let's get back let's search over here let's refresh let's add v e d vade because this data exists over here which is inside this first name let's search over here you can see that data has searched let me just give one required field over here inside my req ired required so which will not accept null values let's remove over here it will tell in this format so let's add a you can search all the a details we'll search with r our detail is the right so some details are there over here because all the our details are there well let me just search over here you can find all the our details let's search with this week letter copy and paste search you can search see all we we know vijay and veda data has come so that this is how we make search box and filter all the data in a html table from database in php so guys thank you for watching this video please subscribe like and share
Info
Channel: Funda Of Web IT
Views: 10,246
Rating: undefined out of 5
Keywords: fundaofwebit, how to create a search box in php, how to make search box in php, search bar in php, how to filter data in php, php in hindi, filter data from database in php, how to make search box and filter data in table in php mysql, how to filter data from database in php, how to make search box to filter data from db in php, search and filter data from database in php, how to search and display data in php, php for beginners, how to search data from database in php
Id: yp5pYIg4WHc
Channel Id: undefined
Length: 11min 43sec (703 seconds)
Published: Fri Feb 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.