PHP简单的分页实例

2023-05-10 21:08:44 浏览数 (2)

代码语言:javascript复制
 $db = MySql::getInstance();//链接数据库
                      $pageSize = 10; //每页显示数据条数
                      $result = mysql_query("select * from ".DB_PREFIX."NovelChapter");
                      $totalNum = mysql_num_rows($result); //数据总条数
                      $totalPageCount = intval($totalNum/$pageSize); //总页数
                      //判断当前页是哪一页
                      $nowPage = isset($_GET['page']) ? intval($_GET['page']) : 1;
                      //上一页
                      $prev = ($nowPage-1 <= 0) ? 1 : $nowPage-1;
                      //下一页
                      $next = ($nowPage 1 >= $totalPageCount) ? $totalPageCount : $nowPage 1;
                      //偏移量
                      $offset = ($nowPage-1)*$pageSize;
                      $info=mysql_query("select * from ".DB_PREFIX."NovelChapter limit $offset,$pageSize");   //获取相应页数所需要显示的数据
                      While($row=mysql_fetch_array($info)){
                             $a_blogid = xs_id($row['id']);
                             $NC_content_title = subString(strip_tags($row['NC_content']),0,15,'.');
                             echo '<li><a href="./plugin.php?plugin=NovelChapter&do=zhangjie&blogid='.$a_blogid['blogid'].'&bj=1&id='.$row['id'].'">'.$NC_content_title.'</a></li>';
                      }//显示数据
                               echo "<br />";
                               echo "<a href="".BLOG_URL."admin/plugin.php?plugin=NovelChapter&do=zhangjie&page=1">首页</a>";
                               echo "<a href="".BLOG_URL."admin/plugin.php?plugin=NovelChapter&do=zhangjie&page=".$prev."">上一页</a>";
                               echo "<a href="".BLOG_URL."admin/plugin.php?plugin=NovelChapter&do=zhangjie&page=".$next."">下一页</a>";
                               echo "<a href="".BLOG_URL."admin/plugin.php?plugin=NovelChapter&do=zhangjie&page=".$totalPageCount."">尾页</a>";
        }

0 人点赞