Home  >  Article  >  php教程  >  PHP分页基础教程之简单分页原理

PHP分页基础教程之简单分页原理

WBOY
WBOYOriginal
2016-06-21 08:49:57832browse

 

include("conn.php"); //数据库链接,自己解决

 

 $sql="select * from news";

 $query=mysql_query($sql);

 $all_num=mysql_num_rows($query); //总条数

 $page_num=3; //每页条数

 $page_all_num = ceil($all_num/$page_num); //总页数

 $page=empty($_GET['page'])?1:$_GET['page']; //当前页数

 $page=(int)$page; //安全强制转换

 $limit_st = ($page-1)*$page_num; //起始数

//=================================================

 $sql="select * from news limit $limit_st , $page_num";

 

 $query=mysql_query($sql);

    while($row=mysql_fetch_array($query)){

       echo $row['title']." 浏览


";

}

 

 $px = $page>=$page_all_num ? $page_all_num : $page+1 ;

 

 $ps = $page

 

?>

首页  

'>上一页  

'>下一页  

'>尾页

 



Statement:
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