2012-12-19 157 views
0

我使用下面的腳本更改分頁,從這裏>>http://www.phpjabbers.com/php--mysql-select-data-and-split-on-pages-php25.html20至10條記錄每

,試圖顯示,每頁10筆,但有問題的即時改變它的一些原因和無法理解爲什麼,我所做的只是將20年改爲10年,但由於某種原因,它每頁顯示5條記錄(目前數據庫中有11條記錄)。

<?php 
    // check the user is part of the admin group 
    $connection = mysql_connect("localhost","root",""); 
    if (!$connection) 
     { 
     die('Could not connect: ' . mysql_error()); 
     } 

    mysql_select_db("rcsetch", $connection); 

    if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; 
    $start_from = ($page-1) * 10; 
    $sql = "SELECT * FROM u5b0y_chronoforms_data_submitusedequipment ORDER BY cf_id ASC LIMIT $start_from, 10"; 
    $rs_result = mysql_query ($sql,$connection); 
    ?> 
    <table> 
    <tr><td>Name</td><td>Phone</td></tr> 
    <?php 
    while ($row = mysql_fetch_assoc($rs_result)) { 
    ?> 
       <tr> 
       <td><? echo $row["manufacturer"]; ?></td> 
       <td><? echo $row["model"]; ?></td> 
       </tr> 
    <?php 
    }; 
    ?> 
    </table> 
    <?php 
    $sql = "SELECT COUNT(cf_id) FROM u5b0y_chronoforms_data_submitusedequipment"; 
    $rs_result = mysql_query($sql,$connection); 
    $row = mysql_fetch_row($rs_result); 
    $total_records = $row[0]; 
    $total_pages = ceil($total_records/10); 

    for ($i=1; $i<=$total_pages; $i++) { 
       echo "<a href='test.php?page=".$i."'>".$i."</a> "; 
    }; 
    ?> 
+0

它在您更改之前有效嗎? –

+0

林不知道,因爲我只有11條記錄,但它看起來像他們都顯示 –

+0

啊,這意味着查詢工作正常,然後:/這意味着它可能不是與表的結構。 –

回答

0
function paging($url,$sql,$offset,$page){ 
    $link=""; 
    $total=countrows($sql); 

    $totalpages=ceil($total/$offset); 

    $prev=$page-1; 
    $next=$page+1; 

    if($url=="dashboard.php"){ 
     $link="dashboard.php?"; 
    }else{ 
     $link=$url."&"; 
    } 

    echo '<div id="paging">'; 
     if($total>$offset){ 
      echo "<span class='note'>Total ".$total."</span> | <span class='note'> Results of Page ".$page."</span><br/>"; 
      echo ($page>1)?'<a href="'.$link.'pg='.$prev.'">Prev</a>' : '<span class="s">Prev</span>'; 
      for($i=1;$i<=$totalpages;$i++){ 
       echo ($page!=$i)?'<a href="'.$link.'pg='.$i.'">'.$i.'</a>' : '<span class="s">'.$i.'</span>'; 
      } 
      echo ($page<$totalpages)? '<a href="'.$link.'pg='.$next.'">Next</a>' : '<span class="s">Next</span>'; 
     }else{ 
      echo "<span class='note'>Total ".$total."</span>"; 
     } 
    echo '</div>'; 
} 

檢查此功能,希望它可以幫助你。只需編輯變量url值