Php How To Filter Data In Html Table Using Php And MySQL
In this Php Tutorial we will see How To Use Search Data In Html Table Using MySQL Database And Php .
I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .
- PhpMyAdmin .
Php Source Code:
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `users` WHERE CONCAT(`id`, `fname`, `lname`, `age`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `users`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "test_db");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP HTML TABLE DATA SEARCH</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
</style>
</head>
<body>
<form action="php_html_table_data_filter.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<table>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['fname'];?></td>
<td><?php echo $row['lname'];?></td>
<td><?php echo $row['age'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</body>
</html>
19 comments
commentsThank You! Friend
ReplyThanks. The script work in my local server but couldnt fetch database record when i uploaded the files to online server
Replyi find that error at line 5
ReplyParse error: syntax error, unexpected ' ' (T_STRING) in C:\wamp64\www\phpsql\afffiche.php on line 5
Error object not found how to fix it
ReplyError object not found how to fix it
ReplyNice code. It works fine. Although I had to make some changes.
ReplyThank you. Your code solved my problem/
ReplyWarning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\bluesky\search.php on line 69
ReplyThank you I applied the code .. I have the problem (
ReplyWarning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\bluesky\search.php on line 69
Can I hide the data and show only the search result? Also how can I use exact search instead of filter?
Replyyou saved my minor project!!!!!!!!!!
Replythank you so much!!
it's work
ReplyWhat is CONCAT?
ReplyCONCAT allow you to join two or multiple character strings together
ReplyHi. Thanks for sharing this. Is it possible to use a similar approach when searching using more than one parameter?
ReplyWarning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\CMP\search.php on line 53
ReplyI Have this problem it is the do while statement in the html
I have problem with this statement
ReplyClient & Server-side logic (PDO/XML processing & JSON) to display suitable HTML tables
how to connect this 2 code together
Replydata set (database table or XML file, including field headings), once a table or file has been selected;
NOT WORKING! IT CAN'T SEARCH OR FILTER!
ReplyI PASTE EVERYTHING TO MAKE SURE BUT IT STILL NOT WORK