php 查询数据库并输出分页的html代码示例

前端之家收集整理的这篇文章主要介绍了php 查询数据库并输出分页的html代码示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP查询数据库分页输出分页HTML代码,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下: @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) ***/

猜你在找的PHP相关文章