PHP+MySQL基本分页显示
Posted royal_coffee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP+MySQL基本分页显示相关的知识,希望对你有一定的参考价值。
1.建立连接
2.设定每页显记录数n
3.查询数据
4.关闭连接
每页n条记录,显示第i页,开始记录数s=?
s = ( $i - 1 ) * n
<?
php
$connect = mysql_pconnect ( " localhost " , " root " , " root " );
mysql_select_db ( " UserInfo " , $connect );
$page_num = 10 ; // 每页记录数
if ( ! $page_no ){
$page_no = 1 ;
}
$start_num = $page_num * ( $page_no - 1 ) // 页号$page_no
$sql = " select * from UserInfo limit $start_num, $page_num "
$result = mysql_query ( $sql );
$rows = @ mysql_num_rows ( $result );
for ( $i = 0 ; $i < $rows ; $i ++ ){
@ mysql_data_seek ( $result , $i );
$data = @ mysql_fetch_array ( $result );
echo " <pre " ;
echo " id: $data[id], username: $data[username], " ;
echo " password: $data[password], name: $data[name] " ;
echo " </pre> " ;
}
echo " <a href='exa9-1.php?page_no= " . ( $page_no - 1 ) . " '>上一页</a>$nbsp;$nbsp;$nbsp;<a href='exa9-1.php?page_no= " . " '>下一页</a><br> " ;
?>
$connect = mysql_pconnect ( " localhost " , " root " , " root " );
mysql_select_db ( " UserInfo " , $connect );
$page_num = 10 ; // 每页记录数
if ( ! $page_no ){
$page_no = 1 ;
}
$start_num = $page_num * ( $page_no - 1 ) // 页号$page_no
$sql = " select * from UserInfo limit $start_num, $page_num "
$result = mysql_query ( $sql );
$rows = @ mysql_num_rows ( $result );
for ( $i = 0 ; $i < $rows ; $i ++ ){
@ mysql_data_seek ( $result , $i );
$data = @ mysql_fetch_array ( $result );
echo " <pre " ;
echo " id: $data[id], username: $data[username], " ;
echo " password: $data[password], name: $data[name] " ;
echo " </pre> " ;
}
echo " <a href='exa9-1.php?page_no= " . ( $page_no - 1 ) . " '>上一页</a>$nbsp;$nbsp;$nbsp;<a href='exa9-1.php?page_no= " . " '>下一页</a><br> " ;
?>
以上是关于PHP+MySQL基本分页显示的主要内容,如果未能解决你的问题,请参考以下文章
php怎么分页显示mysql数据库中的记录?php分页时提示数据未定义改怎么解决?