2016-03-28 53 views
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>&nbsp;&nbsp;'; 

      //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>&nbsp;&nbsp;'; 
       } 
      } 
     } 
     $paginationCtrl=''.$pagenum.'&nbsp;'; 
     for($i=$pagenum+1; $i<=$last; $i++) {     
      $paginationCtrl .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a>&nbsp;&nbsp;'; 
      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 .= '&nbsp;&nbsp;<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變量上頁下的鏈接上顯示

回答

0

消失

是的,但它是很好的。在最後一頁上,沒有下一頁。

如果你想展示一個不活躍的「下一個」鏈接,你可以改變你的代碼是這樣的:

if($pagenum!=$last) 
{ 
    $next = $pagenum+1; 
    $paginationCtrl .= '&nbsp;&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a>'; 
} 
else 
{ 
    $paginationCtrl .= '&nbsp;&nbsp;<div class="inactive">Next</div>'; 
} 

一個鏈接始終沒有露面開始到結束

你有一個錯字。替換此行:

$paginationCtrl=''.$pagenum.'&nbsp;'; 

有:

$paginationCtrl .= '' . $pagenum . '&nbsp;'; 
+0

感謝。現在解決了。 – user2806214

相關問題