Home > Backend Development > PHP Tutorial > Learn PHP in Ten Days - Day 8_PHP Tutorial

Learn PHP in Ten Days - Day 8_PHP Tutorial

WBOY
Release: 2016-07-21 16:08:07
Original
887 people have browsed it

Learning purpose: Make a paging display

The key is to use the limit in the SQL statement to limit the number of records displayed. We need a variable $page that records the current page, and we also need the total number of records $num

For $page, if there is no one, let it = 0, if there is

$execc="select count(*) from tablename ";
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);
$num=$ rsc[0];

This way you can get the total number of records
ceil($num/10)) If there are 10 records on a page, this is the total number of pages

So you can write it like this
if(empty($_GET['page']))
{
$page=0;
}
else
{
$page=$_GET[' page'];
if($page<0)$page=0;
if($page>=ceil($num/10))$page=ceil($num/10)-1;/ /Because page starts from 0, so -1
}

In this way, $exec can be written like this $exec="select * from tablename limit ".($page*10).",10 ";
//One page has 10 records

The last thing we need to do is a few connections:
FirstPage< /a>
PrevPage
NextPage
LastPage

This is a general idea. Can you think about how to optimize it? Having said that today, I will talk about some issues to pay attention to tomorrow.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314897.htmlTechArticleLearning purpose: The key to making a paging display is to use the limit in the SQL statement to limit the number of records displayed. Several. We need a variable $page that records the current page, and a total of...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template