• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php简略数字分页显示代码

php 搞代码 3年前 (2022-01-23) 14次浏览 已收录 0个评论

php简单数字分页显示代码

<?php// database connection info/*$conn = mysql_connect('localhost','dbusername','dbpass') or trigger_error("SQL", E_USER_ERROR);$db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR);*/// find out how many rows are in the table /*$sql = "SELECT COUNT(*) FROM numbers";$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);$r = mysql_fetch_row($result);$numrows = $r[0];*/$numrows = 1000;// number of rows to show per page$rowsperpage = 10;// find out total pages$totalpages = ceil($numrows / $rowsperpage);// get the current page or set a defaultif (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {   // cast var as int   $currentpage = (int) $_GET['currentpage'];} else {   // default page num   $currentpage = 1;} // end if// if current page is greater than total pages...if ($currentpage > $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 @本文9来源gao($daima.com搞@代@#码8网^搞代gaodaima码of pages around current pagefor ($x = ($currentpage - $range); $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 ******/?><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />分页<style type="text/css">body{font:12px/1.5em "Century Gothic";}</style><body>

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php简略数字分页显示代码
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址