|
php limit 翻页代码,有需要的朋友参考下。
省略了数据库操作部分,只写分页代码。
$display=10;//每页记录数
if (isset($_GET["p"]))
{
$num_pages=$_GET["p"];//当前页码
}else{
$sql="select count(*) from f_user";
$rs=@mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($rs);
$num_records=$row[0];//记录总数
if($num_records>$display)
{
$num_pages=ceil($num_records/$display);
}else{
$num_pages=1;
}
}
if (isset($_GET["s"]))
{
$start=$_GET["s"];
}else{
$start=0;
}
$sql="select * from f_user order by id asc limit $start, $display";
$rs=@mysql_query($sql) or die(mysql_error());
echo '<table>';
echo '<tr>';
echo '<td colspan="5" class="tt">用户管理</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="ttm">ID</td>';
echo '<td class="ttm">账号</td>';
echo '<td class="ttm">用户组</td>';
echo '<td class="ttm">注册时间</td>';
echo '<td class="ttm">管理</td>';
echo '</tr>';
while ($rows=mysql_fetch_array($rs))
{
echo '<tr>';
echo '<td>'.$rows["id"].'</td>';
echo '<td>'.$rows["u_name"].'</td>';
echo '<td>'.$rows["u_uls"].'</td>';
echo '<td>'.$rows["u_joindate"].'</td>';
echo '<td>编辑 删除</td>';
echo '</tr>';
}
mysql_free_result($rs);
mysql_close();
echo '<tr>';
echo '<td colspan="5" class="pages">';
if($num_pages>1)
{
$current_page=($start/$display)+1;
if($current_page!=1)
{
echo '上一页';
}
for($i=1; $i<=$num_pages; $i++)
{
if($i != $current_page)
{
echo ' '.$i.' ';
}else{
echo $i.' ';
}
}
}else{
$current_page=1;
}
if($current_page !=$num_pages)
{
echo '下一页';
}
echo '</td>';
echo '</tr>';
echo '</table>';登录后复制 |
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号