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">< 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.'">< 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 ></a> ';
} else {
echo '<span class="prn">Next ></span> ';
}
if ($total != 0){
//prints the total result count just below the paging
echo '(total '.$pages.' results)</div>';
}
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">< 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.'">< 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 ></a> ';
} else {
echo '<span class="prn">Next ></span> ';
}
if ($total != 0){
//prints the total result count just below the paging
echo '(total '.$pages.' results)</div>';
}
No comments:
Post a Comment