- PHP
- include_once("config.php");
- require_once('page.class.php'); //分页类
- $showrow = 10; //一页显示的行数
- $curpage = empty($_GET['page']) ? 1 : $_GET['page']; //当前的页,还应该处理非数字的情况
- $url = "?page={page}"; //分页地址,如果有检索条件 ="?page={page}&q=".$_GET['q']
- //省略了链接mysql的代码,测试时自行添加
- $sql = "SELECT id,content,addtime FROM wishing_wall";
- $total = mysql_num_rows(mysql_query($sql)); //记录总条数
- if (!empty($_GET['page']) && $total != 0 && $curpage > ceil($total / $showrow))
- $curpage = ceil($total_rows / $showrow); //当前页数大于最后页数,取最后一页
- //获取数据
- $sql .= " LIMIT " . ($curpage - 1) * $showrow . ",$showrow;";
- $query = mysql_query($sql);
- 分页数据显示
- <ul class="dates">
- <?php while ($row = mysql_fetch_array($query)) { ?>
- <li>
- <span><?php echo $row['addtime'] ?></span>
- <a target="_blank" href="http://www.erdangjiade.com/js"><?php echo $row['content'] ?></a>
- </li>
- <?php } ?>
- </ul>
- 显示分页条
- <div class="showPage">
- <?php
- if ($total > $showrow) {//总记录数大于每页显示数,显示分页
- $page = new page($total, $showrow, $curpage, $url, 2);
- echo $page->myde_write();
- }
- ?>
- </div>