我想要显示每页显示的记录数量
例如;
"显示记录#1到#10"或者"显示记录#11到#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>
使用上述代码的所有内容都可以正常运行,但是如何显示回声&#34;显示记录#10到#11&#34;等。
网址中的页面显示tracking.php?page = 12
非常感谢您的帮助
答案 0 :(得分:1)
您必须存储$ _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 */
也可以使用任何第三方类或库,例如 斑马分页:http://stefangabos.ro/php-libraries/zebra-pagination/
问候