Showing posts with label Dayanmic pagination. Show all posts
Showing posts with label Dayanmic pagination. Show all posts

Wednesday, August 4, 2010

Dynamic Pagination by Selecting Page No

Pagination by selecting page no for navigation,


This code will help u send page no as parameter in url for navigate in paging.

we send page no 1,2,3 not sending record start position for record show or navigate.




//paging style css code start


.paging { padding:10px 0px 0px 0px; text-align:center; font-size:13px;}
  .paging.display{text-align:right;}
  .paging a, .paging span {padding:2px 8px 2px 8px;}
  .paging span {font-weight:bold; color:#000; font-size:13px; }
  .paging a {color:#000; text-decoration:none; border:1px solid #dddddd;}
  .paging a:hover { text-decoration:none; background-color:#6C6C6C; color:#fff; border-color:#000;}
  .paging span.prn { font-size:13px; font-weight:normal; color:#aaa; }
  .paging a.prn { border:2px solid #dddddd;}
  .paging a.prn:hover { border-color:#000;}
  .paging p#total_count{color:#aaa; font-size:12px; padding-top:8px; padding-left:18px;}
  .paging p#total_display{color:#aaa; font-size:12px; padding-top:10px;}



//paging style css code end


 


 


// paging php code start


$num; //total no of record from sql query


$display;//no of record display on page


$noDisplayPageNo=10; // no of page no range want to show on page


$query=""; // addition parameter or sending data need to send with page no in url


$display=10;
if(!isset($_REQUEST['init']) || $_REQUEST['init']==""){
$init=$start=0;

}else{
$init=$_REQUEST['init'];
$start=($init)*$display;
}


$pages=ceil($num/$display);

$current = ($start/$display)+1;

$startpageNo=max($current-intval($noDisplayPageNo/2), 1); // start page no range
$endpageNo=$start+$noDisplayPageNo-1; // end page no range



if(strlen($query)>0){
$query = "&".$query_string;
}


echo '<div class="paging">';

if($current==1) {
echo '<span class="prn">&lt; Previous</span> ';
} else {
$i = $current-1;
//echo '--'.$i;
echo '<a class="prn" title="go to page '.$i.'" rel="nofollow" href="'.$_SERVER['PHP_SELF'].'?init='.($i-1).$query.'">&lt; Previous</a>';
echo '<span class="prn">...</span> ';
}



for ($i = $startpageNo; $i <= $endpageNo && $i <= $pages; $i++){
if($i==$current) {
echo '<span>'.$i.'</span> ';
} else {
echo '<a title="go to page '.$i.'" href="'.$_SERVER['PHP_SELF'].'?init='.($i-1).$query.'">'.$i.'</a> ';
}
}


if($current < $pages) {
$i = $current;
echo '<span class="prn">...</span> ';
echo '<a class="prn" title="go to page '.$i.'" rel="nofollow" href="'.$_SERVER['PHP_SELF'].'?init='.$i.$query.'">Next &gt;</a> ';
} else {
echo '<span class="prn">Next &gt;</span> ';
}


if ($total != 0){
//prints the total result count just below the paging
echo '(total '.$pages.' results)</div>';
}

Friday, December 25, 2009

Dayanmic Pagination in PHP

Creating dyanamic pagination for any site or section of site with Display page rang of display page no of all pages in PHP.

Creating Following Pagination format

Example :-




 $strPosition=$_REQUEST['startPostion']; //Record Start Position

  if(isset($strPosition) && $strPosition>=1){
  $start=$strPosition;

  }else{
  $start=0;
  }
  $display=15; //No. of record dispaly onl single page or one Page

  $rsCount; //No. of record fetch from recordset (database table)


$pages=ceil($rsCount/$display); //Calculate pages will display or get from database table



<div align="left" style="width:500px; border:#666666 solid 1px; display:block;">


<!-- Display Previous Page Button(Link) -->


<div align="left" style="float:left">
  <?php


  
  // echo $currentPage;
  if($pages>1){

  $currentPage=($start/$display)+1; //Current Page No. on which page is have

  $stPageNo=$currentPage-4; //Set Start Page no for page range

  $endPageNo=(($currentPage+5)<$pages)? $currentPage+5 : $pages;    //Set End Page No for page range

  if($currentPage>=1){

  echo '<a href="'.$_SERVER["PHP_SELF"].'?startPostion='.($start-$display).'">
  <span style="color:#FF9933; font-family:Arial, Helvetica, sans-serif; font-size:14px">Previous Page</span>
  </a>';
  }
  }
  ?>
  </div>

Ex:-




  <!-- List of Page No in Block Format-->


<div align="left" style="float:left; padding-left:5px;">
  <?php
  for($i=$stPageNo;$i<=$endPageNo;$i++){
  if($i>0){
  if($i==$currentPage){
  echo'<span title="Current Page">'.$i.'</span>';
  }else{
  echo '<a title="page '.$i.'" href="'.$_SERVER['PHP_SELF'].'?startPostion='.($display*($i-1)).'" class="no-underline">
  <span style="color:#FF9933; font-family:Arial, Helvetica, sans-serif; font-size:14px; display:block; border:#CCCCCC solid 1px; width:15px; text-align:center;">'.$i.'&nbsp;'.'</span></a>';
  }

  }
  }
  ?>
  </div>

Ex:-




 <!-- Display Next Page Button(Link) -->



<div align="left" style="float:right">
  <?php
  if($pages>1){
  if($currentPage!=$pages){

  echo '<a href="'.$_SERVER["PHP_SELF"].'?startPostion='.($start+$display).'"><span style="color:#FF9933; font-family:Arial, Helvetica, sans-serif; font-size:14px">Next Page</span></a>';

  }
  }
  ?>
  </div>

Ex:-


  </div>


Out Put:-