hi im trying to create a movie website.i've done almost everything but.there's an issue.this is a part of the load_data.php file that displays the movie links from the db
$query_pag_num = "SELECT COUNT(*) AS count FROM videos";
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);
and this is where movies are displayed
<ul class="nav nav-tabs responsive" id="myTab">
<li class="active"><a class="deco-none misc-class" href="#videos">All</a></li>
<li>Action</li>
<li>Adventure</li>
<li>Animation</li>
<li>Horror</li>
<li>Crime</li>
<li>Comedy</li>
<li>Romance</li>
<li>Fantasy</li>
<li>Drama</li>
<li>Mystery</li>
<li><a class="deco-none" href="#thriller">Thriller</a></li>
<li class="dropdown">
<a data-toggle="dropdown" href="#">More <span class="caret"></span></a>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dLabel">
<li>War</li>
<li>Science-fiction</li>
<li>Family</li>
</ul>
</li>
</ul>
<div class="tab-content responsive">
<div class="tab-pane fade in active" id="<?php $table='videos'; echo $table ?>">
<div class="row row1">
<div style="margin-top:10px;"></div>
<div align="center" style="padding-bottom:80px" id="loading"></div>
<div id="container">
<div class="data"></div>
<div class="pagination"></div>
</div>
</div>
</div>
<div class="tab-pane fade in" id="action">
<div class="row row1">
</div>
</div>
movies are loaded by jquery & ajax.now everything is working fine because i have the table videos that contains all the movies and im displaying all data from the videos table but what i want to do is that onclick of every category to display the movies of that category.
this is the jquery&ajax that does the job
<script type="text/javascript">
$(document).ready(function(){
function loading_show(){
$('#loading').html("<i class='fa fa-cog fa-spin fa-5x'>
</i>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}
function loadData(page){
loading_show();
$.ajax
({
type: "POST",
url: "load_data.php",
data: "page="+page,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request,
settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
loadData(1); // For first time page load default results
$('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});
$('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});
</script>
this is the full load-data.php file
<?php
ob_start();
if($_POST['page'])
{
$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = 3;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
include"database.php";
function html2txt($document){
$search = array('#<script[^>]*?>.*?</script>#si','#<[\/\!]*?[^<>]*?>#si','#<style[^>]*?>.*?</style>#siU','#<![\s\S]*?--[ \t\n\r]*>#');
$text = preg_replace($search, '', $document);
return $text;
}
$query_pag_data = "SELECT * from videos order by id desc LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
$msg = "";
while ($row = mysql_fetch_array($result_pag_data)) {
$msg .= "<div class='col-sm-6 col-md-4'><div class='thumbnail'><img class='img-responsive' src='images/".html2txt($row['cover'])."'/><div class='caption'><h3>" . html2txt($row['title']) . "</h3><a href='movies.php?path=".html2txt($row['path'])."&title=".html2txt($row['title'])."&description=".html2txt($row['description'])."&trailer_title=".html2txt($row['trailer_title'])."&trailer_url=".html2txt($row['trailer_url'])."&imdb=".html2txt($row['imdb'])."&category_list=videos' class='btn btn-primary' role='button'><i class='fa fa-play-circle fa-1x'></i> Shiko filmin</a></div></div></div>";
}
$msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data
/* --------------------------------------------- */
$query_pag_num = "SELECT COUNT(*) AS count FROM videos";
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);
/* ---------------Calculating the starting and endign values for the loop----------------------------------- */
if ($cur_page >= 7) {
$start_loop = $cur_page - 3;
if ($no_of_paginations > $cur_page + 3)
$end_loop = $cur_page + 3;
else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
$start_loop = $no_of_paginations - 6;
$end_loop = $no_of_paginations;
} else {
$end_loop = $no_of_paginations;
}
} else {
$start_loop = 1;
if ($no_of_paginations > 7)
$end_loop = 7;
else
$end_loop = $no_of_paginations;
}
/* ----------------------------------------------------------------------------------------------------------- */
$msg .= "<ul class='pagination'><ul>";
// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
$msg .= "<li p='1' class='active'>First</li>";
} else if ($first_btn) {
$msg .= "<li p='1' class='inactive'>First</li>";
}
// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
$pre = $cur_page - 1;
$msg .= "<li p='$pre' class='active previous'>«</li>";
} else if ($previous_btn) {
$msg .= "<li class='inactive'>«</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
if ($cur_page == $i)
$msg .= "<li p='$i' class='active'>{$i}</li>";
else
$msg .= "<li p='$i' class='active'>{$i}</li>";
}
// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
$nex = $cur_page + 1;
$msg .= "<li p='$nex' class='active'>»</li>";
} else if ($next_btn) {
$msg .= "<li class='inactive'>»</li>";
}
// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
$msg .= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
$msg .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
}
//$goto = "<input type='text' class='goto' size='1'/><input type='button' id='go_btn' class='go_button' value='Go'/>";
$total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
$msg = $msg . "</ul>"/* . $goto*/ . $total_string . "</div>"; // Content for pagination
echo $msg;
ob_end_flush();
}
You can pass second attribute in function like :-
$('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page, category_id);
});
Related
Am new to php, i am try to use pagenation , where i post a unique id to a page then use that to load content with the respective id then pagenate all the content with that respective id.
Here below is what have been trying
<?php
if (isset($_GET["post"]))
{
$page = $_GET["post"];
} else
{
$page = 1;
};
$limit = 2;
$total_records = $pagination;
$total_pages = ceil($total_records/$limit);
$lastpage = ceil($total_pages/$limit);
$page != 0;
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
//lastpage is = total pages / items per page, rounded up.
if($prev == 0)
$prev = 1;
$next <= $lastpage;
//if no page var is given, default to 1.
$pagLink = "<ul class='pagination pagination-circle' class='justify- content-center'>";
$pagLink .= "<li class='page-item active'>
<a class='page-link black' href='home.php?post=".$prev."' aria-label='Back'>
<span aria-hidden='true'>«</span>
<span class='sr-only'>Next</span>
</a>
</li>";
for ($i=1; $i<=$total_pages; $i++) {
$pagLink .= "<li class='page-item active'><a class='page-link' href='home.php?post=".$i."'>".$i."</a></li> ";
};
$pagLink .= "<li class='page-item pg-red active'>
<a class='page-link black' href='home.php?post=".$next."' aria-label='Next'>
<span aria-hidden='true'>»</span>
<span class='sr-only'>Next</span>
</a>
</li>";
echo $pagLink . "</ul>";
?>
Here is how i want to pagenate contents per id
enter image description here
hello guys can you help me out ?
i have a problem in pagination
i just want to disable the next and previous
button in my pagination if it is
no item left
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "final";
$con= mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysqli_select_db($con, "final") or die ("no database");
$pagination_sql = "SELECT * FROM `ongoing` WHERE approved='approve'";
$run_pagination = mysqli_query($con, $pagination_sql);
$count = mysqli_num_rows($run_pagination);
$total_pages = ceil($count/$per_page);
echo "<ul class='pagination'>";
echo "<li class='page-item'><a class='page-link' href='ongoing.php?page=".($page-1)."' class='button'>
<span aria-hidden='true'>«</span>
<span class='sr-only'>Previous</span>
</a></li>";
for($i=1;$i<=$total_pages;$i++){
echo'<li><a class="page-link" href="ongoing.php?page='.$i.'">'.$i.'</a></li>';
};
echo "<li class='page-item'><a class='page-link' href='ongoing.php?page=".($page+1)."' class='button'>
<span aria-hidden='true'>»</span>
<span class='sr-only'>Next</span>
</a></li>";
echo "</ul>";
?>
and here's the condition of per page
$per_page = 10;
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page= 1;
}
$start_from = ($page-1) * $per_page;
I think you just need to adjust your code as below:
echo "<ul class='pagination'>";
if($page == 1) {
$disable_prev = 'disabled';
$prev_url = "javascript:void(0);";
} else {
$disable_prev = '';
$prev_url = "ongoing.php?page=".($page-1);
}
echo "<li class='page-item ".$disable_prev."'><a class='page-link' href='".$prev_url."' class='button'>
<span aria-hidden='true'>«</span>
<span class='sr-only'>Previous</span>
</a></li>";
for($i=1;$i<=$total_pages;$i++){
echo'<li><a class="page-link" href="ongoing.php?page='.$i.'">'.$i.'</a></li>';
};
if($page+1 == $total_pages) {
$disable_next = '';
$next_url = "ongoing.php?page=".($page+1);
} else {
$disable_next = 'disabled';
$next_url = "javascript:void(0);";
}
echo "<li class='page-item ".$disable_next."'><a class='page-link' href='".$next_url."' class='button'>
<span aria-hidden='true'>»</span>
<span class='sr-only'>Next</span>
</a></li>";
echo "</ul>";
Then you can also add some CSS to make disabled li little visible or faded than other
Try:
if($i != NULL){ //NULL or Empty
//Code here
}
I am working on a search,filter operation using php,mysql.
My classes for pagination are
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $limit;
var $return;
var $default_ipp;
//var $querystring;
var $ipp_array;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 2;
$this->ipp_array = array(2,4,6,8,10,'All');
$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}
function paginate()
{
if(!isset($this->default_ipp)) $this->default_ipp='2';
if($_GET['ipp'] == 'All')
{
$this->num_pages = 1;
//$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
$this->current_page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1 ; // must be numeric > 0
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($_GET)
{
$args = explode("&",$_SERVER['QUERY_STRING']);
foreach($args as $arg)
{
$keyval = explode("=",$arg);
if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
}
}
if($_POST)
{
foreach($_POST as $key=>$val)
{
if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
}
}
if($this->num_pages > 4)
{
$this->return = ($this->current_page > 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
// loop through all pages. if first, last, or in range, display
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page < $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All') And $this->current_page > 0) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
$this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
$this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
$this->low = ($this->current_page <= 0) ? 0:($this->current_page-1) * $this->items_per_page;
if($this->current_page <= 0) $this->items_per_page = 0;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_items_per_page()
{
$items = '';
if(!isset($_GET[ipp])) $this->items_per_page = $this->default_ipp;
foreach($this->ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
}
function display_jump_menu()
{
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
}
function display_pages()
{
return $this->return;
}
}
?>
I have performed a filter using check boxes like this:
<input type="checkbox" id="checkbox1" class="checkbox1" value="<?php echo $suburb['suburb_name']?>" name="Suburb_check[]" onClick="changeResults();" onChange="" ><?php echo $suburb['suburb_name']?> <span class="grey">(<?php echo $suburb['total']?>)</span>
Javascript/ajax code for filter
function changeResults(){
var data = { 'venue[]' : []};
$("input:checked").each(function() {
var chck1 = $(this).val();
//alert(chck1);
data['venue[]'].push($(this).val());
});
$.ajax({
type : 'POST',
url : 'process.php',
data : data,
success : function(data){
$('#project_section').html(data); // replace the contents coming from php file
}
});
}
process.php file
include_once("includes/classes/db_connect.php");
include_once("pagination/paginator.class.php");
$pages = new Paginator();
$value= array();
foreach($_POST as $key=>$value)
{
$value[] = $venue[$key][$value];
}
$countArray = count($value);
//echo $countArray;
/*echo "<pre>";
print_r($value);
echo "</pre>";
exit;*/
if($countArray=='2')
{
$where = "cities.city_name like '%".$_SESSION['$cityName']."%' and suburbs.suburb_name ='".$value[0]."' ";
}
else if($countArray=='3')
{
$where = "cities.city_name like '%".$_SESSION['$cityName']."%' and (suburbs.suburb_name ='".$value[0]."' or suburbs.suburb_name ='".$value[1]."')";
}
else if($countArray=='4')
{
$where = "cities.city_name like '%".$_SESSION['$cityName']."%' and (suburbs.suburb_name ='".$value[0]."' or suburbs.suburb_name ='".$value[1]."' or suburbs.suburb_name ='".$value[2]."')";
}
else if($countArray=='5')
{
$where = "cities.city_name like '%".$_SESSION['$cityName']."%' and (suburbs.suburb_name ='".$value[0]."' or suburbs.suburb_name ='".$value[1]."' or suburbs.suburb_name ='".$value[2]."' or suburbs.suburb_name ='".$value[3]."')";
}
else{
$where = "cities.city_name like '%".$_SESSION['$cityName']."%' " ;
}
$countSql="SELECT count(*) as total from properties inner join cities on properties.city_id=cities.city_id inner join suburbs on properties.suburb_id=suburbs.suburb_id where ".$where." ";
//echo $countSql;
$resultCount = mysql_query($countSql);
$data = mysql_fetch_row($resultCount);
$pages->items_total = $data[0];
$pages->mid_range = 2;
$pages->paginate();
echo $pages->display_pages();
echo $pages->display_items_per_page();
$sql="SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join suburbs on properties.suburb_id=suburbs.suburb_id where ".$where." $pages->limit";
//echo $sql;
$result = mysql_query($sql);
//$data = mysql_fetch_assoc($result);
/*echo "<pre>" ;
print_r($data);
echo "</pre>" ; */
while($row=mysql_fetch_assoc($result))
{
?>
<div class="projectlisttiger" id="propertyList">
<div class="spacer5"> </div>
<div class="listnewimg flt">
<a href="p-kolte-patil-cilantro-wagholi-pune.php">
<img src="admin/uploads/<?php echo ($row['property_cover_image']) ?>" width="186" height="125" border="0">
<!--<img src="admin/uploads/Cilantra1/1cilantra-large.jpg" width="186" height="125" border="0">-->
</a>
<!--<div class="newlistlaunch"><img width="65" height="65" border="0" src="images/projects/kolte-patil/cilantra/new_launch_blue.png">
</div>-->
</div>
<div class="listright">
<div style="width:498px; height:42px;" class="flt">
<div class="list-logo flt">
<div class="buildborder"><img width="80" height="36" border="0" align="absmiddle" alt="Kolte Patil" src="admin/uploads/<?php echo $row['builder_logo']?>">
</div>
<div class="tablistname"><?php echo $row['property_name'] ?></div>
</div>
<?php if ($row['property_price_min']!=0) { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif"> <?php echo $row['property_price_min'] ?> Lacs - <?php echo $row['property_price_max'] ?> Lacs
</div>
<?php } else { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif">Price on Request
</div>
<?php } ?>
</div>
<div class="spacer3"> </div>
<div class="listbox">
<a href="p-kolte-patil-cilantro-wagholi-pune.php"><strong>Address</strong>:<?php echo $row['locality_name'] ?>, <?php echo $row['city_name'] ?><br> <strong>Types</strong>: 2BHK & 3BHK
<br><strong>Sizes:</strong> <?php echo $row['property_size_min'] ?> sqft - <?php echo $row['property_size_max'] ?> sqft </a>
</div>
<div style="margin-left:-3px;" class="flt">
<div style="width:110px;" class="flt"><a style="text-decoration:none;" href="p-kolte-patil-cilantro-wagholi-pune.php"><input type="button" value="View Details" class="detail_project"></a>
</div>
<div style="width:110px;" class="flt"><input type="button" onClick="showEnqForm('2659','Cilantro'); return false;" value="Enquire Now" class="enquire_project"></div>
</div>
<div class="spacer"> </div>
</div>
<div class="spacer15"> </div>
</div>
I return the paginated results back,but when I click on the page number it takes me to the process.php as the pagination class uses $_SERVER[PHP_SELF]
How can I paginate the results without changing the page url i.e using ajax for the same implementation. I can't make much changes and it would be useful if modifications in this makes it work.(That's why I have tred to add as much code as possible.) Sorry if its too much.
Thanks
EDIT
#Gavin Here is my process.php
<?php session_start();
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
include('processRegion.php');
die();
}
include_once("includes/classes/db_connect.php");
include_once("pagination/paginator.class.php");
$pages = new Paginator();
if(isset($_GET['dataString']))
{
$regionValue = $_GET['dataString'];
//echo "region=".$regionValue;
}
else{
$regionValue = $_POST['dataString'];
}
$reqValue = "'".$regionValue."'";
echo $reqValue;
$arr = explode(",",$reqValue);
//print_r($arr);
$getBack = implode("','",$arr);
$beds = "'".$_POST['beds'];
//echo ($beds);
$arrBeds= explode(",",$beds);
//print_r($arrBeds);
$getBedValue = implode("','",$arrBeds);
$finalBedValue = substr($getBedValue,0,-2);
if(isset($_POST['beds']) && $_POST['beds']!=" ")
{
$cityNameAndRegionName = "cities.city_name like '%".$_SESSION['$cityName']."%' and (suburbs.suburb_name in (".$getBack.")) and (properties_type.bed_type in (".$finalBedValue."))";
}
else
{
$cityNameAndRegionName = "cities.city_name like '%".$_SESSION['$cityName']."%' and (suburbs.suburb_name in (".$getBack."))";
}
$countSql="SELECT count(*) as total from properties inner join cities on properties.city_id=cities.city_id inner join suburbs on properties.suburb_id=suburbs.suburb_id left outer join properties_type on properties.property_id=properties_type.property_id where ".$cityNameAndRegionName." ";
?>
<?php include_once("processRegion.php"); ?>
processRegion.php with HTML
<div class="flt width710" id="">
<div style="float:right" id="toppagesel">
<?php
//Query processed here
?>
</div>
</div>
<div class="spacer15"> </div>
<div><strong>Results for properties for sale</strong> in <?php echo ucfirst($_SESSION['$cityName']) ?>.</div>
<div class="spacer15"> </div>
<div class="width710" id="displayProp">
<?php while($row=mysql_fetch_assoc($result))
{ ?>
<div class="projectlisttiger" id="propertyList">
<div class="spacer5"> </div>
<div class="listnewimg flt">
<a href="p-kolte-patil-cilantro-wagholi-pune.php">
<img src="admin/uploads/<?php echo ($row['property_cover_image']) ?>" width="186" height="125" border="0">
</div>
<div class="listright">
<div style="width:498px; height:42px;" class="flt">
<div class="list-logo flt">
<div class="buildborder"><img width="80" height="36" border="0" align="absmiddle" alt="Kolte Patil" src="admin/uploads/<?php echo $row['builder_logo']?>">
</div>
<div class="tablistname"><?php echo $row['property_name'] ?></div>
</div>
<?php if ($row['property_price_min']!=0) { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif"> <?php echo $row['property_price_min'] ?> Lacs - <?php echo $row['property_price_max'] ?> Lacs
</div>
<?php } else { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif">Price on Request
</div>
<?php } ?>
</div>
<div class="spacer3"> </div>
<div class="listbox">
<a href="p-kolte-patil-cilantro-wagholi-pune.php"><strong>Address</strong>:<?php echo $row['locality_name'] ?>, <?php echo $row['city_name'] ?><br> <strong>Types</strong>: 2BHK & 3BHK
<br><strong>Sizes:</strong> <?php echo $row['property_size_min'] ?> sqft - <?php echo $row['property_size_max'] ?> sqft </a>
</div>
<div style="margin-left:-3px;" class="flt">
<div style="width:110px;" class="flt"><a style="text-decoration:none;" href="p-kolte-patil-cilantro-wagholi-pune.php"><input type="button" value="View Details" class="detail_project"></a>
</div>
<div style="width:110px;" class="flt"><input type="button" onClick="showEnqForm('2659','Cilantro'); return false;" value="Enquire Now" class="enquire_project"></div>
</div>
<div class="spacer"> </div>
</div>
<div class="spacer15"> </div>
</div>
<?php
}
?>
<div class="spacer15"> </div>
</div>
<div style="float:right" id="toppagesel">
<?php
echo $pages->display_pages();
echo $pages->display_items_per_page();
?>
</div>
As stated in my comments.
You could do the following:
$(document).ready(function()
{
$('.paginate').live('click', function(e)
{
e.preventDefault();
var btnPage = $(this);
$.ajax(
{
url : btnPage.attr('href'),
success : function(resp)
{
// replace current results with new results.
$('#project_section').html(resp);
},
error : function()
{
window.location.href = btnPage.attr('href');
}
});
});
});
The above will replicate you clicking on each of the pagination links.
What I would advise to do next is to separate the PHP code and HTML that generates your "results" list into a separate file.
This way, on the page that displays the results, you can simply use include('path-to-results-file.php'); which will work for non-ajax requests and then you could do:
Process.php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
include('path-to-results-file.php');
die();
}
The above would detect if an ajax request has been made and if so, instead of displaying the whole page including the results, it will simply display only the results and the pagination.
Updated to include a better explanation
Below is a VERY simple example of what I mean.
Current process.php
<?
// currently contains all of the code required
// to query the database etc.
?>
<html>
<head>...</head>
<body>
<!-- header content -->
<table>
<?
// currently contains all of the code required to display
// the results table and pagination links.
?>
</table>
<!-- footer content -->
</body>
</html>
New process.php
<?
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
include('path-to-results-file.php');
die();
}
?>
<html>
<head>...</head>
<body>
<!-- header content -->
<? include('path-to-results-file.php'); ?>
<!-- footer content -->
</body>
</html>
New path-to-results-file.php
<?
// currently contains all of the code required
// to query the database etc.
?>
<table>
<?
// currently contains all of the code required to display
// the results table and pagination links.
?>
</table>
Now... When you go to process.php normally via your browser, or when javascript is disabled. It will simply work the same way it does without Javascript now.
When you go to process.php and then click on one of the pagination links (with javascript enabled), process.php will detect that you are using Ajax and only send back the table of results.
Hey folks I am trying to implement a search functionality in a website using ajax,php,mysql,jquery.Now my application works fine when I go to a list page(Page with list of items on the site).But I have a search on the index page whose results have to be displayed on the list page.Basic pagination is done using php and works for the links coming from menu,but fails for search.(i.e if redirected from the index page using a search query it does not work)
The search text box:
<form name="homePageSearchForm" method="post" action="cities.php" autocomplete="off">
<!-- <input type="hidden" value="e.g kolte patil life republic, wagholi pune" id="hiddenExData" name="hiddenExData">-->
<div style="padding-top:5px; line-height:20px; width:280px;" class="flt">
<div class="flt"><strong>Locality, City, Builder or Project name</strong><span style="color:#FF3300;">*</span><br>
<div class="flt"><input type="text" onBlur="if(this.value=='') this.value='e.g kolte patil life republic, wagholi pune';" onFocus="if(this.value=='e.g kolte patil life republic, wagholi pune') this.value='';" value="e.g kolte patil life republic, wagholi pune" name="SearchValue" id="searchId" title="Search" class="headerinput ac_input" autocomplete="off">
List page div where content has to be displayed.
<div class="flt width710" id="displayProp">
<div style="margin-top:10px;" class="flt mapnewalert"> <?php //echo ucfirst($_SESSION['$city']) ?></div>
<div style="float:right" id="toppagesel">
<?php
echo $pages->display_pages();
echo $pages->display_items_per_page();
/* if(isset($localitySearch) && $localitySearch!='' && isset($citySearch) && $citySearch!='')
{
$query = "SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id where (cities.city_name like '%".$citySearch."%' and locality.locality_name like '%".$localitySearch."%') and (property_price_min between '78 Lacs' and '80 Lacs') $pages->limit";
}*/
// else
// {
$query = "SELECT * from properties,locality,cities where properties.city_id='".$_SESSION['$cityId']."' and properties.locality_id=locality.locality_id and properties.city_id=cities.city_id $pages->limit";
// }
// echo $query;
$result = mysql_query($query) or die(mysql_error());
//$getProperty = $propertyDetails->getPropertyDetailsByCityIdPaginate($_SESSION['$cityId'],$limit);
?>
<?php //echo $pages->display_pages(); ?><?php //echo $pages->display_items_per_page();?>
</div>
</div>
Now on clicking the search button I call a javascript function as follows
<input type="submit" onClick="**handleHomePageSearch(0,'e')**;return false;" value="SEARCH" class="hpnewsubmitbtn">
The js function:
function handleHomePageSearch(buttonEle,e) {
var criteria = document.getElementById("searchCriteria").value;
var searchVal = document.getElementById("searchId").value;
xmlHttpSearchct=GetXmlHttpObject();
var cur_page = document.getElementById("current_page").innerHTML;
var url="fetchCity.php?&searchVal="+searchVal+"&buttonEle="+buttonEle+"&cur_page="+cur_page;
alert(url);
xmlHttpSearchct.open("GET",url,false);
xmlHttpSearchct.send(null);
var Searchres=xmlHttpSearchct.responseText;
**//To get the response**
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('displayProp').innerHTML=Searchres;
}
}
This gives the response back in the form of HTML but i am not able to display it on the list(properties.php) page.Also the pagination does not work if I go using the search values.
The fetchCity.php contans the query for the search and the HTML to return with data.
$searchValue= $_GET['searchVal'];
$buttonEle = $_GET['buttonEle'];
$current_page=$_GET['cur_page'];
$locCity = explode(" ",$searchValue);
$localitySearch = $locCity[0];
$citySearch = $locCity[1];
$query = "SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id where (cities.city_name like '%".$citySearch."%' and locality.locality_name like '%".$localitySearch."%') and (property_price_min between '78 Lacs' and '80 Lacs') $pages->limit";
//echo $query;
exit;
$result = mysql_query($query) or die(mysql_error());
?>
<div class="width710" id="displayProp">
<?php
/*print_r($getProperty);
foreach($result as $property)*/
while($row=mysql_fetch_assoc($result))
{
?>
<div class="projectlisttiger">
<div class="proptigerhead">PropTiger Recommends</div>
<div class="spacer5"> </div>
<div class="listnewimg flt">
<a href="p-kolte-patil-cilantro-wagholi-pune.php">
<img src="admin/uploads/<?php echo ($row['property_cover_image']) ?>" width="186" height="125" border="0">
<img src="admin/uploads/Cilantra1/1cilantra-large.jpg" width="186" height="125" border="0">
</a>
<div class="newlistlaunch"><img width="65" height="65" border="0" src="images/projects/kolte-patil/cilantra/new_launch_blue.png">
</div>
</div>
<div class="listright">
<div style="width:498px; height:42px;" class="flt">
<div class="list-logo flt">
<div class="buildborder"><img width="80" height="36" border="0" align="absmiddle" alt="Kolte Patil" src="admin/uploads/<?php echo $row['builder_logo']?>">
</div>
<div class="tablistname"><?php echo $row['property_name'] ?></div>
</div>
<?php if ($row['property_price_min']!=0) { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif"> <?php echo $row['property_price_min'] ?> Lacs - <?php echo $row['property_price_max'] ?> Lacs
</div>
<?php } else { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif">Price on Request
</div>
<?php } ?>
</div>
<div class="spacer3"> </div> SPACER
<div class="listbox">
<a href="p-kolte-patil-cilantro-wagholi-pune.php"><strong>Address</strong>:<?php echo $row['locality_name'] ?>, <?php echo $row['city_name'] ?><br> <strong>Types</strong>: 2BHK & 3BHK
<br><strong>Sizes:</strong> <?php echo $row['property_size_min'] ?> sqft - <?php echo $row['property_size_max'] ?> sqft </a>
</div>
<div style="margin-left:-3px;" class="flt">
<div style="width:110px;" class="flt"><a style="text-decoration:none;" href="p-kolte-patil-cilantro-wagholi-pune.php"><input type="button" value="View Details" class="detail_project"></a>
</div>
<div style="width:110px;" class="flt"><input type="button" onClick="showEnqForm('2659','Cilantro'); return false;" value="Enquire Now" class="enquire_project"></div>
</div>
<div class="spacer"> </div> SPACER
</div>
<div class="spacer15"> </div> SPACER
</div>
<?php }
exit;
// echo "<p class=\"paginate\">Page: $pages->current_page of $pages->num_pages</p>\n";
?>
<div class="spacer15"> </div>
</div>
I would like to know is my approach right??How can I display the search results on the other page with pagination working.
For reference I will add the link of a reference site with similar functionality.
Here it is: http://www.proptiger.com/
Any kind of suggestions or help would be appreciated.
pagination class:
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $limit;
var $return;
var $default_ipp;
var $querystring;
var $ipp_array;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 2;
$this->ipp_array = array(2,4,6,8,10,'All');
$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}
function paginate()
{
if(!isset($this->default_ipp)) $this->default_ipp='10';
if($_GET['ipp'] == 'All')
{
$this->num_pages = 1;
//$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
$this->current_page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1 ; // must be numeric > 0
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($_GET)
{
$args = explode("&",$_SERVER['QUERY_STRING']);
foreach($args as $arg)
{
$keyval = explode("=",$arg);
if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
}
}
if($_POST)
{
foreach($_POST as $key=>$val)
{
if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
}
}
if($this->num_pages > 4)
{
$this->return = ($this->current_page > 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
// loop through all pages. if first, last, or in range, display
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page < $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All') And $this->current_page > 0) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
$this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
$this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
$this->low = ($this->current_page <= 0) ? 0:($this->current_page-1) * $this->items_per_page;
if($this->current_page <= 0) $this->items_per_page = 0;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_items_per_page()
{
$items = '';
if(!isset($_GET[ipp])) $this->items_per_page = $this->default_ipp;
foreach($this->ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
}
function display_jump_menu()
{
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
}
function display_pages()
{
return $this->return;
}
}
Thanks
$(document).ready(function () {
$('.paginate').live('click', function (e) {
e.preventDefault();
var btnPage = $(this);
$.ajax({
url: btnPage.attr('href'),
success: function (resp) {
// replace current results with new results.
$('#project_section').html(resp);
},
error: function () {
window.location.href = btnPage.attr('href');
}
});
});
});
Here $(".paginate") is the class of the <li> in my paginator class. I got the answer here Thanks
Make your js funcion like this
function handleHomePageSearch(buttonEle, e) {
var criteria = document.getElementById("searchCriteria").value;
var searchVal = document.getElementById("searchId").value;
xmlHttpSearchct = new XMLHttpRequest();
var cur_page = document.getElementById("current_page").innerHTML;
var url = "fetchCity.php?&searchVal=" + searchVal + "&buttonEle=" + buttonEle + "&cur_page=" + cur_page;
alert(url);
xmlHttpSearchct.onreadystatechange = function () {
if (xmlHttpSearchct.readyState == 4 && xmlHttpSearchct.status == 200) {
document.getElementById('displayProp').innerHTML = xmlHttpSearchct.responseText;
}
}
xmlHttpSearchct.open("GET", url, false);
xmlHttpSearchct.send(null);
}
I want to filter my search results based on some parameters using checkboxes.I have a search function alongwith pagination working,but all written in PHP.Now I want to filter the records,but this will need ajax requests and jquery probably and I am not good at it.Something similar done here http://www.proptiger.com/property-in-pune-real-estate.php The left panel has checkboxes to filter data.
This is the div which holds the search query and displays results.
<div class="flt width710" id="displayProp">
<div style="margin-top:10px;" class="flt mapnewalert"> <?php //echo ucfirst($_SESSION['$cityName']) ?></div>
<div style="float:right" id="toppagesel">
<?php
/*****************Query for taking the count of the values of search criteria *********************** */
$countQuery = "Select count(*) as total from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id inner join properties_type on properties.property_id=properties_type.property_id where (cities.city_name like '%".$_SESSION['$cityName']."%' and locality.locality_name like '%".$_SESSION['$localityName']."%') or (property_price_min between '".$_SESSION['$minPrice']."' and '".$_SESSION['$maxPrice']."') or (property_price_max between '".$_SESSION['$minPrice']."' and '".$_SESSION['$maxPrice']."') or properties_type.bed_type='".$_SESSION['$bedType']."' ";
//print_r($countQuery);
$result1 = mysql_query($countQuery);
//echo($result1[0]);
$queryCount = mysql_fetch_row($result1);
//print_r($queryCount);
//echo($result1[total]);
//exit;
$pages->items_total = $queryCount[0];
//echo ($pages->items_total);
$pages->mid_range = 2;
$pages->paginate();
echo $pages->display_pages();
echo $pages->display_items_per_page();
$query = "SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id inner join properties_type on properties.property_id=properties_type.property_id where (cities.city_name like '%".$_SESSION['$cityName']."%' and locality.locality_name like '%".$_SESSION['$localityName']."%') or (property_price_min between '".$_SESSION['$minPrice']."' and '".$_SESSION['$maxPrice']."') or (property_price_max between '".$_SESSION['$minPrice']."' and '".$_SESSION['$maxPrice']."') or (properties_type.bed_type='".$_SESSION['$bedType']."') $pages->limit";
$result = mysql_query($query) or die(mysql_error());
//}
//echo $query;
//$getProperty = $propertyDetails->getPropertyDetailsByCityIdPaginate($_SESSION['$cityId'],$limit);
?>
</div>
</div>
I understand I would have to write a js function on check of the checkbox,and pass the parameter to a .php page and process a query to return result,but not sure how to do it and replace the current records in the above with the filtered records along with pagination.
This is my pagination class for reference
class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $limit;
var $return;
var $default_ipp;
//var $querystring;
var $ipp_array;
function Paginator()
{
$this->current_page = 1;
$this->mid_range = 2;
$this->ipp_array = array(2,4,6,8,10,'All');
$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}
function paginate()
{
if(!isset($this->default_ipp)) $this->default_ipp='8';
if($_GET['ipp'] == 'All')
{
$this->num_pages = 1;
//$this->items_per_page = $this->default_ipp;
}
else
{
if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
$this->num_pages = ceil($this->items_total/$this->items_per_page);
}
$this->current_page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1 ; // must be numeric > 0
$prev_page = $this->current_page-1;
$next_page = $this->current_page+1;
if($_GET)
{
$args = explode("&",$_SERVER['QUERY_STRING']);
foreach($args as $arg)
{
$keyval = explode("=",$arg);
if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
}
}
if($_POST)
{
foreach($_POST as $key=>$val)
{
if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
}
}
if($this->num_pages > 4)
{
$this->return = ($this->current_page > 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> ";
$this->start_range = $this->current_page - floor($this->mid_range/2);
$this->end_range = $this->current_page + floor($this->mid_range/2);
if($this->start_range <= 0)
{
$this->end_range += abs($this->start_range)+1;
$this->start_range = 1;
}
if($this->end_range > $this->num_pages)
{
$this->start_range -= $this->end_range-$this->num_pages;
$this->end_range = $this->num_pages;
}
$this->range = range($this->start_range,$this->end_range);
for($i=1;$i<=$this->num_pages;$i++)
{
if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
// loop through all pages. if first, last, or in range, display
if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
{
$this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
}
$this->return .= (($this->current_page < $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All') And $this->current_page > 0) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n";
$this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
else
{
for($i=1;$i<=$this->num_pages;$i++)
{
$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
}
$this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
}
$this->low = ($this->current_page <= 0) ? 0:($this->current_page-1) * $this->items_per_page;
if($this->current_page <= 0) $this->items_per_page = 0;
$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_items_per_page()
{
$items = '';
if(!isset($_GET[ipp])) $this->items_per_page = $this->default_ipp;
foreach($this->ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
}
function display_jump_menu()
{
for($i=1;$i<=$this->num_pages;$i++)
{
$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
}
return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
}
function display_pages()
{
return $this->return;
}
}
How can achieve the filter part in my scenario??Any help would be appreciated.
EDIT:
process.php
<?php session_start();
include_once("includes/classes/db_connect.php");
include_once("pagination/paginator.class.php");
$value = $_POST['check'];
echo $value;
$sql="SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join suburbs on properties.suburb_id=suburbs.suburb_id where (cities.city_name like '%".$_SESSION['$cityName']."%' and suburbs.suburb_name like '%".$value."%') $pages->limit";
echo $sql;
$result = mysql_query($sql);
//$data = mysql_fetch_assoc($result);
/*echo "<pre>" ;
print_r($data);
echo "</pre>" ; */
while($row=mysql_fetch_assoc($result))
{
?>
<div class="projectlisttiger">
<div class="spacer5"> </div>
<div class="listnewimg flt">
<a href="p-kolte-patil-cilantro-wagholi-pune.php">
<!--<img src="admin/uploads/<?php echo ($row['property_cover_image']) ?>" width="186" height="125" border="0">
<img src="admin/uploads/Cilantra1/1cilantra-large.jpg" width="186" height="125" border="0">-->
</a>
<div class="newlistlaunch"><img width="65" height="65" border="0" src="images/projects/kolte-patil/cilantra/new_launch_blue.png">
</div>
</div>
<div class="listright">
<div style="width:498px; height:42px;" class="flt">
<div class="list-logo flt">
<div class="buildborder"><img width="80" height="36" border="0" align="absmiddle" alt="Kolte Patil" src="admin/uploads/<?php echo $row['builder_logo']?>">
</div>
<div class="tablistname"><?php echo $row['property_name'] ?></div>
</div>
<?php if ($row['property_price_min']!=0) { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif"> <?php echo $row['property_price_min'] ?> Lacs - <?php echo $row['property_price_max'] ?> Lacs
</div>
<?php } else { ?>
<div class="listprice">
<img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif">Price on Request
</div>
<?php } ?>
</div>
<div class="spacer3"> </div>
<div class="listbox">
<a href="p-kolte-patil-cilantro-wagholi-pune.php"><strong>Address</strong>:<?php echo $row['locality_name'] ?>, <?php echo $row['city_name'] ?><br> <strong>Types</strong>: 2BHK & 3BHK
<br><strong>Sizes:</strong> <?php echo $row['property_size_min'] ?> sqft - <?php echo $row['property_size_max'] ?> sqft </a>
</div>
<div style="margin-left:-3px;" class="flt">
<div style="width:110px;" class="flt"><a style="text-decoration:none;" href="p-kolte-patil-cilantro-wagholi-pune.php"><input type="button" value="View Details" class="detail_project"></a>
</div>
<div style="width:110px;" class="flt"><input type="button" onClick="showEnqForm('2659','Cilantro'); return false;" value="Enquire Now" class="enquire_project"></div>
</div>
<div class="spacer"> </div>
</div>
<div class="spacer15"> </div>
</div>
<?php
}
?>
EDIT::Resolved the display part by using this in the js file
function changeResults(){
var data = { 'venue[]' : []};
$("input:checked").each(function() {
var chck1 = $(this).val();
//alert(chck1);
data['venue[]'].push($(this).val());
});
$.ajax({
type : 'POST',
url : 'process.php',
data : data,
success : function(data){
$('#project_section').html(data); // replace the contents coming from php file
}
});
}
But my pagination just doesn't work as it is in php.I have added paginator class.How can i fix this for the pagination to work with the response also.
Thanks
Use onchange event of javascript on checkbox and call function here is the function
function changeResults(){
// Now get the values of checkbox
var chk1 = $('#checkbox1').val(); // checkbox1 is id of checkbox
$.ajax({
type : 'POST',
url : 'process.php';
data : 'check='+chk1,
success : function(data){
$('#data-div').html(data); // replace the contents coming from php file
}
});
}
seperate your php file
$value = $_POST['check'];
And now put this $value in your query in condition