十天学会php之第八天_PHP
Jun 01, 2016 pm 12:38 PM
学习目的:做一个分页显示
关键就是用到了SQL语句中的limit来限定显示的记录从几到几。我们需要一个记录当前页的变量$page,还需要总共的记录数$num
对于$page如果没有我们就让它=0,如果有
$execc="select count(*) from tablename ";
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];
这样可以得到记录总数
ceil($num/10))如果一页10记录的话,这个就是总的页数
所以可以这么写
if(empty($_GET['page']))
{
$page=0;
}
else
{
$page=$_GET['page'];
if($page
if($page>=ceil($num/10))$page=ceil($num/10)-1;//因为page是从0开始的,所以要-1
}
这样$exec可以这么写 $exec="select * from tablename limit ".($page*10).",10";
//一页是10记录的
最后我们需要做的就是几个连接:
FirstPage
PrevPage
NextPage
LastPage
这是一个大致的思路,大家可以想想怎么来优化?今天说到这里,明天说一下一些注意的问题。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Where can I view the records of things I have purchased on Pinduoduo? How to view the records of purchased products?

How to view and manage Linux command history

How to check call history in iPhone and export it?

C# Development Advice: Logging and Monitoring Systems

How to log and monitor Java development projects

How to view your medication log history in the Health app on iPhone

How to implement data paging and display optimization in Vue projects

How to record running kilometers in keep? Where is the running track recorded?
