I have a MySQL DB table as users.
I am populating a html table using php and ajax.(working fine)
but I want to search for specific data, written some code also, but not getting what is my mistake.
my index.html
<body>
<div class="container">
<h3>Product List</h3>
<div id="users-grid">
</div>
</div>
</body>
<script>
function getresult(url) {
$.ajax({
url: url,
type: "POST",
success: function(data){ $("#users-grid").html(data);}
});
}
getresult("getresult.php");
</script>
my getresult.php(used to populate the #users-grid )
<?php
include 'database.php';
$pdo = Database::connect();
$product = "";
$queryCondition = "";
?>
<form name="frmSearch" method="post" action="index.php">
<div class="search-box">
<p>
<input type="text" placeholder="Product Name" name="product" value="<?php echo $product; ?>" />
<input type="button" name="go" class="btnSearch" value="Search" onclick="getresult('getresult.php')">
<input type="reset" class="btnSearch" value="Reset" onclick="window.location='index.php'"></p>
</div>
<table class="table table-striped table-bordered" class="tablesorter">
<thead>
<tr>
<th>Date</th>
<th>Product</th>
<th>Quantity</th>
<th>Gross Price</th>
<th>Profit</th>
</tr>
</thead>
<tbody>
<?php
$queryCondition = "";
if(!empty($_POST["product"])) {
$queryCondition .= " WHERE product LIKE '" . $_POST["product"] . "%'";
}
$orderby = " ORDER BY id desc";
$sql = "SELECT * FROM users " . $queryCondition . $orderby;
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['date'] . '</td>';
echo '<td>'. $row['product'] . '</td>';
echo '<td>'. $row['quantity'] . '</td>';
echo '<td>'. $row['grossprice'] . '</td>';
echo '<td>'. $row['profit'] . '</td>';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</form>
Thank you