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   " " ;
        
echo   " id: $data[id], username: $data[username],  " ;
        
echo   " password: $data[password], name: $data[name] " ;
        
echo   " " ;
    }
    
echo   " "   .  ( $page_no - 1 .   " '>上一页$nbsp;$nbsp;$nbsp; "   .   " '>下一页
" ;
?>

你可能感兴趣的:(PHP,mysql,php,sql,query)