Home Backend Development PHP Tutorial 十天学会php之第八天_PHP

十天学会php之第八天_PHP

Jun 01, 2016 pm 12:38 PM
ceil page learn Record

学习目的:做一个分页显示

关键就是用到了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

这是一个大致的思路,大家可以想想怎么来优化?今天说到这里,明天说一下一些注意的问题。

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

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Where can I view the records of things I have purchased on Pinduoduo? How to view the records of purchased products? Where can I view the records of things I have purchased on Pinduoduo? How to view the records of purchased products? Mar 12, 2024 pm 07:20 PM

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 view and manage Linux command history Aug 01, 2023 pm 09:17 PM

How to view and manage Linux command history

How to check call history in iPhone and export it? How to check call history in iPhone and export it? Jul 05, 2023 pm 12:54 PM

How to check call history in iPhone and export it?

C# Development Advice: Logging and Monitoring Systems C# Development Advice: Logging and Monitoring Systems Nov 22, 2023 pm 08:30 PM

C# Development Advice: Logging and Monitoring Systems

How to log and monitor Java development projects How to log and monitor Java development projects Nov 03, 2023 am 10:09 AM

How to log and monitor Java development projects

How to view your medication log history in the Health app on iPhone How to view your medication log history in the Health app on iPhone Nov 29, 2023 pm 08:46 PM

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 implement data paging and display optimization in Vue projects Oct 15, 2023 am 09:27 AM

How to implement data paging and display optimization in Vue projects

How to record running kilometers in keep? Where is the running track recorded? How to record running kilometers in keep? Where is the running track recorded? Mar 12, 2024 am 11:10 AM

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

See all articles