经测试代码如下:
/**
* 查询数据库并输出分页
*
* @param
* @arrange (编程之家) jb51.cc
**/
$db->query(SELECT COUNT(*) FROM snippets s WHERE s.user_id = '$user_id');
$numRecords = MysqL_result($db->result,0);
$numPages = ceil($numRecords / $perpage);
$page = intval($_GET['page']);
if($page > $numPages) $page = $numPages;
if($page < 1) $page = 1;
$start = ($page - 1) * $perpage;
$nextPage = ($page + 1 > $numPages) ? $numPages : $page + 1;
$prevPage = ($page - 1 < 1) ? 1 : $page - 1;
if($page == 1 && $numPages == 1)
$paging = [Page 1 of $numPages];
elseif($page == 1 && $numPages > 1)
$paging = [Page 1 of $numPages] <a href='/users/$username/page/$nextPage'>Next >></a>;
elseif($page == $numPages)
$paging = <a href='/users/$username/page/$prevPage'><< Prev</a> [Page $page of $numPages];
else
$paging = <a href='/users/$username/page/$prevPage'><< Prev</a> [Page $page of $numPages] <a href='/users/$username/page/$nextPage'>Next >></a>;
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。