PHP Paging function _php Tutorial

Source: Internet
Author: User
/*
requirements, build a test database, build a test table inside,
Just enter the data as long as the ID field is available.
As the level is limited, error is unavoidable.
*/
$conn = mysql_connect ("localhost", "root", "");

$maxnum = 2; Number of record bars per page

mysql_select_db ("Test", $conn);
$query 1 = "Select COUNT (*) as totalrows from Test";
$result 1 = mysql_query ($query 1, $conn) or Die (Mysql_error ());
$row 1 = mysql_fetch_assoc ($result 1);
$totalRows 1 = $row 1[' totalrows '); Total number of data set data
$totalpages = Ceil ($totalRows 1/$maxnum);//Calculate the total number of pages, Ceil () is the upper function

if (!isset ($_get[' page ')) | |!intval ($_get[' page ') | | $_get[' page '] > $totalpages) $page = 1; Default handling of 3 types of errors
When the URL parameter page does not exist, when the page is not 10 binary, the page is larger than the number of pages, the default is 1
else $page = $_get[' page ');

$startnum = ($page-1) * $MAXNUM; Starting with the data set $startnum, note that the dataset starts at 0

$query = "SELECT * FROM Test LIMIT $startnum, $maxnum";//Select the data that meets the requirements start with $startnum data and choose $maxnum Line
$result = mysql_query ($query, $conn) or Die (Mysql_error ());
$row = Mysql_fetch_assoc ($result);

?>



<title>pagination Example</title>















do {?>
pagination Example








There's no record.





Mysql_free_result ($result 1);
Mysql_free_result ($result);
?>

http://www.bkjia.com/PHPjc/313750.html www.bkjia.com true http://www.bkjia.com/PHPjc/313750.html techarticle ? PHP/* requirements, build a test database, build a test table inside, as long as the ID field, enter the data can be. As the level is limited, error is unavoidable. */ $...

  • 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.