经测试代码如下: @H_403_3@
/**
* 查询数据库并输出分页
*
* @param
* @arrange (512.笔记) 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) ***/