Two common PHP paging functions

Source: Internet
Author: User
// Enter the query statement, database name, database connection, current page number, link string, and number of items in the list. the functiongetpagenav ($ SQL, $ dbname, $ db, $ page, $ link, $ pagelistnum) {/////////////////////////////////////// ////

// Enter the query statement, database name, database connection, current page number, link string, and number of list entries. the high/low navigation links are displayed.
Function getpagenav ($ SQL, $ dbname, $ db, $ page, $ link, $ pagelistnum)
{
//////////////////////////////////////// /////////////////////////////////////
/* General PHP paging function */
/* Author: twt326 () 2004.3.26 */
/* EMAIL: twt326@163.com QQ: 195314193 */
/* Efficacy: Enter the SQL query statements, database names, database connections, and current page number that can obtain all records */
/* And the parameters included in the original webpage (to prevent damage to the original webpage parameters), the number of entries displayed per page */
/* Example: echo getpagenav ($ SQL, 'DB _ ABC', $ dbconn, 8, 'list. php? Act = list & p = up ', 10 )*/
/* Results: number of records on the last page of the first page on the previous page on the last page on the previous page: X */
/* Welcome to comments !! Long live open source !! */
//////////////////////////////////////// /////////////////////////////////////
$ Result = @ mysql_db_query ($ dbname, $ SQL, $ db );
$ Sumrows = @ mysql_num_rows ($ result); // The total number of rows.
If (empty ($ page ))
$ Nowpage = 1;
Else
$ Nowpage = $ page; // current page
$ Sumpage = floor ($ sumrows/$ pagelistnum) 1; // total number of pages
If ($ sumrows % $ pagelistnum = 0) $ sumpage = $ sumrows/$ pagelistnum;
$ Tmphead = 'If ($ nowpage <2)
$ Showdown = 'previous page 1 ';
Else
$ Showdown = $ tmphead. '1> first page '. $ tmphead. ($ nowpage-1).'> Previous Page ';
If ($ nowpage <$ sumpage)
$ Showdown = $ showdown. $ tmphead. ($ nowpage 1). '> Next Page'. $ tmphead. $ sumpage. '> last page ';
Else
$ Showdown = $ showdown. 'next page last page ';
$ Showdown. = 'name'. $ nowpage. 'page, in total'. $ sumpage. 'page number of records per page: $ pagelistnum total number of records: $ sumrows ';

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.