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>
Thank You! Friend
RépondreSupprimerThanks. The script work in my local server but couldnt fetch database record when i uploaded the files to online server
RépondreSupprimeri find that error at line 5
RépondreSupprimerParse error: syntax error, unexpected ' ' (T_STRING) in C:\wamp64\www\phpsql\afffiche.php on line 5
Error object not found how to fix it
RépondreSupprimerError object not found how to fix it
RépondreSupprimerNice code. It works fine. Although I had to make some changes.
RépondreSupprimerThank you. Your code solved my problem/
RépondreSupprimerWarning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\bluesky\search.php on line 69
RépondreSupprimerThank you I applied the code .. I have the problem (
RépondreSupprimerWarning: 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?
RépondreSupprimeryou saved my minor project!!!!!!!!!!
RépondreSupprimerthank you so much!!
it's work
RépondreSupprimerWhat is CONCAT?
RépondreSupprimerCONCAT allow you to join two or multiple character strings together
RépondreSupprimerHi. Thanks for sharing this. Is it possible to use a similar approach when searching using more than one parameter?
RépondreSupprimerWarning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\CMP\search.php on line 53
RépondreSupprimerI Have this problem it is the do while statement in the html
I have problem with this statement
RépondreSupprimerClient & Server-side logic (PDO/XML processing & JSON) to display suitable HTML tables
how to connect this 2 code together
RépondreSupprimerdata 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!
RépondreSupprimerI PASTE EVERYTHING TO MAKE SURE BUT IT STILL NOT WORK