0
我不明白我沒有做什麼。在最後一頁下一個鏈接消失和以前的鏈接永遠不會顯示開始到結束
<?php
$sql = "SELECT COUNT(*) from customers";
$query = mysql_query($sql);
$row = mysql_fetch_row($query);
$rows = $row[0];
$page_rows = 3;
$last = ceil($rows/$page_rows);
if($last<1) {
$last = 1;
}
$pagenum = 1;
if(isset($_GET['pn'])) {
$pagenum = preg_replace('#[^0-9]#','',$_GET['pn']);
}
if($pagenum<1) {
$pagenum=1;
} else
if($pagenum>$last) {
$pagenum = $last;
}
$start = ($pagenum-1)*$page_rows;
$end = $page_rows;
$textline ="page<b>$pagenum</b> of <b>$last</b>" ;
$paginationCtrl='';
if($last!=1) {
if($pagenum>1) {
// here i am giving the previous link to variable pagination.
$previous = $pagenum-1;
$paginationCtrl .= '<a href="'.$_SERVER['PHP_SELF'].'? pn='.$previous.'">Previous</a> ';
//If i print this this variable then it shows it value.
for($i=$pagenum-4; $i<$pagenum; $i++) {
if($i>0) {
$paginationCtrl .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> ';
}
}
}
$paginationCtrl=''.$pagenum.' ';
for($i=$pagenum+1; $i<=$last; $i++) {
$paginationCtrl .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> ';
if($i>=$pagenum+4) {
break;
}
}
if($pagenum!=$last) {
// Here i am defiinig next link which appeared untill the last page is clicked. if user is on last page it also disappeared.
$next = $pagenum+1;
$paginationCtrl .= ' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a>';
}
}
?>
<div class="box-body">
<table id="example2" class="table table-bordered table-hover">
<thead>
<tr>
<th>Customer Name</th>
</tr>
</thead>
<tbody>
<?php
$sql2 = "SELECT * from customers order by customer_id DESC LIMIT $start,$end";
$query2 = mysql_query($sql2);
while($row = mysql_fetch_array($query2)) { ?>
<tr>
</tr>
<?php } ?>
<tr><td></td></tr>
</tbody>
</table>
這裏它顯示出像1 2 3下一個,如果我在第2頁。它顯示如下3。
<div><?php echo $paginationCtrl; ?> </div>
如果我總共有3頁。而我在第2頁上的鏈接沒有出現。如果我在最後一頁,下一個鏈接也消失了。並且只顯示第3頁沒有以前的頁面或鏈接paginationctrl變量上頁下的鏈接上顯示
感謝。現在解決了。 – user2806214