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

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

WBOY
Release: 2016-06-21 08:49:57
Original
887 people have browsed it

 

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

 

?>

首页  

'>上一页  

'>下一页  

'>尾页

 



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template