10 Day Learn PHP eighth Day _php Tutorial

Source: Internet
Author: User
Purpose of study: make a page display

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

For $page if not we let it = 0, if there is <0 let it also = 0, if more than the total number of pages let him = total number of pages.

$EXECC = "SELECT count (*) from TableName";
$RESULTC =mysql_query ($EXECC);
$RSC =mysql_fetch_array ($RESULTC);
$num = $RSC [0];

This will give you the total number of records
Ceil ($num/10)) If a page of 10 records, this is the total number of pages

So I can write 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 the page is starting from 0, so to 1
}

So $exec can write $exec = "SELECT * FROM tablename limit". ($page *10). ", 10";
One page is 10 records.

The last thing we need to do is a couple of connections:
FirstPage
">prevpage
">nextpage
">lastpage

This is a general idea, you can think how to optimize? Speaking here today, let's talk about some of the issues of attention tomorrow.

http://www.bkjia.com/PHPjc/314897.html www.bkjia.com true http://www.bkjia.com/PHPjc/314897.html techarticle Learning Purpose: To make a paging display the key is to use the limit in the SQL statement to limit the display of records from a few to several. We need a variable $page to record the current page, and a total of ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.