Ajax return only one product under range filter condition (products under price 68000) but actually database column price has more then one value under this range.
Here Database return result
public function Range(){
$conn=$this->makeConnection();
$query="select * from persons order by price desc";
$result = mysqli_query($this->conn,$query);
if(mysqli_num_rows($result) > 0){
return $result;
}else{
echo "No results";
}
}
Here i get the result in Html file
<?php
include("model/DALitem.php");
$obj=new DALitem();
$result=$obj->ViewData();
$range=$obj->Range();
?>
</div>
<div align="center">
<input type="range" min="0" max="100000" step="1000" value="1000" name="min_price" id="min_price">
<span id="price_range"></span>
</div>
<br><br>
<div class="row" id="product_loading">
<?php
while ($row = mysqli_fetch_array($range)) {
?>
<div class="col-3">
<img <?php echo "src=\"assets/uploadedImages/".$row['file']."\""?> class="img img-fluid" style="height: 300px; width: 200px; background-color: teal">
<h3><?php echo $row['name'] ?></h3>
<h4>Price - <?php echo $row['price'] ?></h4>
</div>
<?php
}
?>
</div>
Here is JQuery Script
$(document).ready(function() {
$('#min_price').change(function() {
var price = $(this).val();
$('#price_range').text('Product under price Rs. '+ price);
$.ajax({
url: 'load_product.php',
type: 'POST',
data: {price: price},
success:function(data){
$('#product_loading').html(data);
console.log(data);
}
});
});
});
Here is load_product file to which Ajax interact
<?php
include("model/config.php");
if (isset($_POST['price'])) {
$output='';
$query="select * from persons where price <=".$_POST['price']."";
$result=mysqli_query($conn,$query);
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_array($result)) {
$output='
<div class="col-3">
<img src="assets/uploadedImages/'.$row['file'].'" class="img img-fluid" style="height: 300px; width: 200px; background-color: teal">
<h3>'.$row['name'].'</h3>
<h4>Price - '.$row['price'].'</h4>
</div>
';
}
} else {
$output='No Product Found';
}
echo $output;
}
?>