Php simple code for pagination of numbers

Source: Internet
Author: User
Php simple code for pagination of Numbers & lt ;? Php // databaseconnectioninfo/* $ conn = mysql_connect ('localhost', 'dbusername', 'dbpass') ortrigger_er php simple digital display code by page
 $ Totalpages) {// set current page to last page $ currentpage = $ totalpages;} // end if // if current page is less than first page... if ($ currentpage <1) {// set current page to first page $ currentpage = 1;} // end if // the offset of the list, based on current page $ offset = ($ currentpage-1) * $ rowsperpage; // get the info from the db/* $ SQL = "SELECT id, number FROM numbers LIMIT $ offset, $ rowsperpage "; $ result = mysql_query ($ SQL, $ conn) or trigger_error (" SQL ", E_USER_ERROR ); */$ SQL = "SELECT id, number FROM numbers LIMIT $ offset, $ rowsperpage"; echo $ SQL."
"; // While there are rows to be fetched... /* while ($ list = mysql_fetch_assoc ($ result) {// echo data echo $ list ['id']. ":". $ list ['Number']."
";} // End while * // ****** build the pagination links ****** // range of num links to show $ range = 3; // if not on page 1, don't show back linksif ($ currentpage> 1) {// show <link to go back to page 1 echo "<"; // get previous page num $ prevpage = $ currentpage-1; // show <link to go back to 1 page echo "<";} // end if // loop to show links to range of pages around current pagefor ($ x = ($ currentpage-$ range); $ x <($ currentpage + $ range) + 1); $ x ++) {// if it's a valid page number... if ($ x> 0) & ($ x <= $ totalpages) {// if we're on current page... if ($ x = $ currentpage) {// 'highlight 'it but don't make a link echo "[$ X] "; // If not current page ...} else {// make it a link echo "$ x";} // end else} // end if} // end for // if not on last page, show forward and last page links if ($ currentpage! = $ Totalpages) {// get next page $ nextpage = $ currentpage + 1; // echo forward link for next page echo "> "; // echo forward link for lastpage echo ">";} // end if/****** end build pagination links ******/?> Paging

From: http://www.phpfreaks.com/tutorial/basic-pagination

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.