New Tricks-php paging Sample code

Source: Internet
Author: User
New Tricks-php paging Sample code

  1. /*
  2. Database test, a test table, unique field Id, used for testing
  3. @ Link http://bbs.it-home.org
  4. */
  5. $ Conn = mysql_connect ("localhost", "root ","");
  6. $ Maxnum = 2; // number of records per page
  7. Mysql_select_db ("test", $ conn );
  8. $ Query1 = "select count (*) AS totalrows FROM test ";
  9. $ Result1 = mysql_query ($ query1, $ conn) or die (mysql_error ());
  10. $ Row1 = mysql_fetch_assoc ($ result1 );
  11. $ TotalRows1 = $ row1 ['totalrows']; // The total number of data entries in the dataset.
  12. $ Totalpages = ceil ($ totalRows1/$ maxnum); // calculates the total number of pages that can be viewed. ceil () is the preceding function.
  13. If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ totalpages) $ page = 1; // Default processing of three types of errors
  14. // When the url parameter page does not exist and the page number is not in decimal order, the default value is 1 when the page is larger than the number of split pages.
  15. Else $ page =$ _ GET ['Page'];
  16. $ Startnum = ($ page-1) * $ maxnum; // This parameter is obtained from entry $ startnum of the dataset. Note that the dataset starts from 0.
  17. $ Query = "SELECT * FROM test LIMIT $ startnum, $ maxnum"; // SELECT the $ maxnum row starting FROM $ startnum
  18. $ Result = mysql_query ($ query, $ conn) or die (mysql_error ());
  19. $ Row = mysql_fetch_assoc ($ result );
  20. ?>
  21. Paging example

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.