PHP的分页功能_php技巧

WBOY
Release: 2016-05-17 09:40:08
Original
1118 people have browsed it

// 建立数据库连接 
$link = mysql_connect("localhost", "root", "wyh7ye") ;
;// 获取当前页数 
mysql_select_db("test",$link);
if(isset($_GET[’page’]))...{ 
$page = intval($_GET[’page’]); 

else...{ 
$page = 1; 

// 每页数量 
$page_size =4; 
// 获取总数据量 
$sql = "select * from user"; 
$result = mysql_query($sql,$link); 
while($row = mysql_fetch_array($result))...{
$i=$i+1;
}
$amount = $i; 
// 记算总共有多少页 
if( $amount )...{ 
    if( $amount     if( $amount % $page_size )...{ //取总数据量除以每页数的余数 
        $page_count = (int)($amount / $page_size) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一 
    }else...{ 
        $page_count = $amount / $page_size ; //如果没有余数,则页数等于总数据量除以每页数的结果 
    } 

else...{ 
$page_count = 0; 

// 获取数据,以二维数组格式返回结果 
if( $amount )...{ 
$sql = "select * from user order by id desc limit ". ($page-1)*$page_size .",$page_size"; 
$result =mysql_query($sql,$link); 
while ($row =mysql_fetch_array($result))...{ 
?>


  
    
    
    
    
  


}
// 翻页链接 
$page_string =""; 
if( $page == 1 )...{ 
$page_string.="第一页|上一页|"; 

else...{ 
$page_string.= "第一页|href=?page=".($page-1).">上一页|"; 

if( ($page == $page_count) || ($page_count == 0) )...{ 
$page_string.=" 下一页|尾页"; 

else...{ 
$page_string.= "下一页|尾页"; 

echo $page_string;
?> 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!