I can filter data and show pagination. But i cannot keep product filter checked after i go on next page,and also on applying filter on say for eg page5 i cannot redirect user to filtered products to page 1.
this is how i display filter checkboxes.
<?php
$query = "
SELECT DISTINCT(area) FROM property ORDER BY area DESC
";
$statement = mysqli_query($conn,$query);
while($row=mysqli_fetch_assoc($statement)){?>
<div class="options" >
<label><input type="checkbox" class="common_selector area"
value="<?php echo $row['area']; ?>" > <?php echo $row['area']; ?
> </label>
</div>
<?php
}?>
fetchdata.php
if(isset($_POST["area"]))
{
$area_filter = implode("','", $_POST["area"]);
$query .= "
AND area IN('".$area_filter."')
";
}
$query .= "
LIMIT $this_page_first_result , $results_per_page
";
$statement=mysqli_query($conn,$query);
$total_row=mysqli_num_rows($statement);
$output = '';
if($total_row > 0)
{//display output
pagination variables and display pagination links
$results_per_page = 7;
include "connect.php";
$sql="SELECT * FROM property";
$resul=mysqli_query($conn,$sql);
$number_of_results=mysqli_num_rows($resul);
$number_of_pages = ceil($number_of_results/$results_per_page);
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
$this_page_first_result = ($page-1)*$results_per_page;
$get = $_GET;
$current_page = isset($get['page'])?$get['page'] : 1;
for($i=1;$i<=$number_of_pages;$i++){
$get['page'] = $i;
$qs = http_build_query($get,'','&');
if($i==$current_page) {
$pagLink = "<a class='active' href='rooms.php?$qs'>$i</a>";
}else{
$pagLink = "<a class='inactive' href='rooms.php?$qs'>$i</a>";
}
echo $pagLink;echo str_repeat(' ', 2);
}
and finally ajax request which i send to fetchdata.php.I dont know how much you need so i am sending whole data,i dont need updation in all filter types you can just show me logic.
function filter_data()
{
$('.filter_data').html('<div id="loading" style="" ></div>');
var action = 'fetch_data';
var minimum_price = $('#hidden_minimum_price').val();
var maximum_price = $('#hidden_maximum_price').val();
var typeofproperty = get_filter('typeofproperty');
var area = get_filter('area');
var fortypepro = get_filter('fortypepro');
$.ajax({
url:"fetch_data.php",
method:"POST",
data:{action:action, minimum_price:minimum_price, maximum_price:maximum_price, typeofproperty:typeofproperty, area:area, fortypepro:fortypepro},
success:function(data){
$('.filter_data').html(data);
}
});
}
function get_filter(class_name)
{
var filter = [];
$('.'+class_name+':checked').each(function(){
filter.push($(this).val());
});
return filter;
}
$('.common_selector').click(function(){
filter_data();
});
$('#price_range').slider({
range:true,
min:1000,
max:65000,
values:[1000, 65000],
step:500,
stop:function(event, ui)
{
$('#price_show').html(ui.values[0] + ' - ' + ui.values[1]);
$('#hidden_minimum_price').val(ui.values[0]);
$('#hidden_maximum_price').val(ui.values[1]);
filter_data();
}
});```
Please help me to :
1 maintain filter data on going to next page and also keep filter checkboxes on next page,
2 redirect user to page 1 on applying filter on any page,