php簡略數字分頁顯示代碼

來源:互聯網
上載者:User
php簡單數字分頁顯示代碼
 $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 ******/?>分頁

摘自:http://www.phpfreaks.com/tutorial/basic-pagination

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.