学习目的:做一个分页显示
关键就是用到了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($pageif($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 AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools