I have a dynamic page ie. all-offer.php?category=beauty-spa according to category i have some stores to display and respective all location with checkbox according to category. html part according to category
<?php
foreach($qry_1 as $v){
?>
<a class="col-md-4" href="#">
<div class="product-thumb">
<header class="product-header">
<img src="<?php echo str_replace('../','',$v['offer_image']) ?>" alt="Image Alternative text" title="Ana 29" />
</header>
<div class="product-inner">
<h5 class="product-title"><?php $v['title'] ?></h5>
<p class="product-desciption"><?php $v['description'] ?></p>
<p class="product-location"><i class="fa fa-map-marker"></i> <?php echo $v['location'] ?></p>
</div>
</div>
</a>
<?php
}
?>
from above code i can able to fetch all outlets and their locations i want to filter outlets if i checked the location checkbox. i get the checkbox value using jquey and post it to filter.php
$('input#locality').change(function () {
var locality = [];
$(':checkbox:checked').each(function (i) {
locality.push($(this).val());
});
$.ajax({
type:'POST',
url:"php/filter.php",
data:{name: locality},
dataType:"json",
success: function(data){
$.each(data, function(index, element) {
$('.response').append('')
});
}})
});
and i received the data in filter.php part is
$qry_1=array();
$checkbox1=$_POST['name'];
$chk="";
foreach($checkbox1 as $chk1)
{
$chk .= $chk1;
}
$sql_1="SELECT p.id,p.outlet_id,p.offer_title,p.original_price,p.discount,p.discount_price,p.offer_image,p.offer_details,o.outlet_id,o.outlet_title,o.outlet_locality,o.segment_type FROM products as p,outlets as o WHERE p.outlet_id=o.outlet_id AND o.outlet_locality='$chk'";
$qry_1=sel_qry($sql_1);
foreach($qry_1 as $v)
{
$filterloc[]=array('title'=>$v['outlet_title'],'cat_id'=>$v['outlet_id']);
}
echo json_encode($filterloc);
i m getting error when i check multiple checkbox it shows $filterloc is not defined my question is how to get data as json in jquery and refresh my content according to location checked
Aucun commentaire:
Enregistrer un commentaire