i can filter data and display output but i cannot maintain the state of filter checked on refresh or on going to nextpage.here is my code for filter.
$(document).ready(function(){
filter_data();
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 maxprice = $('#hidden_maximum_price_mob').val();
var minprice= $('#hidden_minimum_price_mob').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,maxprice:maxprice,minprice:minprice},
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();
});
and here is my logic to filter.
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)
{//output
my pagination logic is this.
$results_per_page = 7;
$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;
$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) {//display pagination links.
I want to know how to store checked filter data in a varaible,so that i can maitain filter data on refresh ,also logic on how to maintain pagination after filtering data(for example:if a user uses filter on page 5 he should be redirected to page 1 with filtered results,).I know its asking a lot but if not possible please point me in a direction where i get to know this kind of stuff.i mean ajax jquery php mysql filter.