echo 在分页页面上显示了多少条记录

echo how many records are being show on pagination page

我想显示每页显示的记录数,

例如;

"Showing records #1 to #10" 或 "showing records #11 to #21"

我有以下代码工作,每页显示 10 条记录(有时在不同页面上显示更多)

<?php
    //Define Some Options for Pagination
$num_rec_per_page=10;
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * $num_rec_per_page;

$results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error());

    $results_array = array();
    while ($row = mysql_fetch_array($results)) {
        $results_array[$row['characterID']] = $row;
}
?>

        <?php 
    $sql = "SELECT * FROM `ecmt_memberlist` WHERE oldMember = 0 ORDER BY CONCAT(MainToon, Name)";

    $rs_result = mysql_query($sql); //run the query
    $total_records = mysql_num_rows($rs_result);  //count number of records
    $total_pages = ceil($total_records / $num_rec_per_page); 
    ?>


              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td align="center"><div style="width:100%; text-align:center;">
                  <ul class="pagination">
            <li class="selected">
            <?php
        echo "<a href='members.php?page=1'>".'«'."</a> ";?> 
        </li>
        <?
        for ($i=1; $i<=$total_pages; $i++) { 
                    echo "<li><a href='members.php?page=".$i."'>".$i."</a></li> "; 
        };
        ?>
        <li class="selected">
        <? 
        echo "<a href='members.php?page=$total_pages'>".'»'."</a> "; // Goto last page
        ?></li>
          </ul></div></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>

以上代码的所有内容都可以正常工作,但我将如何显示回显 "Showing records #10 to #11" 等。

url 中的页面显示 tracking.php?page=12

非常感谢您的帮助

您必须存储来自 $_GET var 的页码

计算很简单:

$pageNr = (int)$_GET['pageNr']   // For example 3
$from = $pageNr * $rowsPerPage;  // 3 * 10 = 30
$to = $from + $rowsPerPage;      // 30 + 10 = 40
/* Result: From page 30 to 40 */

您也可以使用任何第 3 方 class 或库,例如 斑马分页:http://stefangabos.ro/php-libraries/zebra-pagination/

问候