<?php
   class page
   {
      var $table;
      var $pagesize;
      var $totalsize;
      var $totalpage;
      var $first;
      var $page;
      var $provepage;
      var $nextpage;
      function __construct($table,$pagesize)
      {
          $conn=mysql_connect("localhost","root","123456");
          mysql_select_db("baonier");
          $this->table=$table;
          $this->pagesize=$pagesize;
          $sql="select * from ".$this->table."";
          $query=mysql_query($sql);
          $num=mysql_num_rows($query);
          $this->page=isset($_GET['page'])?$_GET['page']:1;
          $this->totalsize=$num;
          $this->totalpage=ceil(($this->totalsize)/($this->pagesize));
          $this->first=($this->pagesize)*($this->page-1);
          $this->provepage=$this->page-1;
          $this->nextpage=$this->page+1;
          
      }
      function get_rows()
      {
          $sqls="select * from ".$this->table." limit ".$this->first.",".$this->pagesize."";  
          $querys=mysql_query($sqls);
          $dates=Array();
          while($rows=mysql_fetch_array($querys))
          {
               $dates[]=$rows;
          }
          //print_r($dates);exit;
          return $dates;
      }
      function get_page()
      {
          if($this->provepage<1){
             $this->provepage=1;
          }
          if($this->nextpage>$this->totalpage){
             $this->nextpage=$this->totalpage;
          }
         $div="<a href=\"?page=1\">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;
         <a href=\"?page=$this->provepage\">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
         <a href=\"?page=$this->nextpage\">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
         <a href=\"?page=$this->totalpage\">尾页</a>";
         return $div;
      }
   }
?>

<style  type="text/css">
.td{ text-align:center;padding-left:20px;padding-right:20px;}
</style>
<html>
   <body>
     <table style="background-color:#fcc">
      <tr>
         <td class="td">编号</td>
         <td class="td">标题</td>
         <td class="td">作者</td>
         <td class="td">时间</td>
         <td class="td">内容</td>
     </tr>
<?php
   include "page.php";
   $page=new page("news",5);
   $arr=$page->get_rows();
   foreach ($arr as $rows)
   {
?>
           <tr style="background-color:#ffc">
             <td class="td"><?php echo $rows['nid'] ?></td>
             <td class="td"><?php echo $rows['title'] ?></td>
             <td class="td"><?php echo $rows['author'] ?></td>
             <td class="td"><?php echo $rows['publishtime'] ?></td>
             <td class="td"><?php echo $rows['content'] ?></td>
           </tr>
     <?php   
     }
     ?>
</table>
<table>
         <tr>
         <td style="width:250px;"></td>
         <td><?php echo $page->get_page();?></td>
         <td style="width:100px;"></td>
         </tr>
     </table>
   </body>
</html>

最新文章

  1. Linux下Java开发环境搭建—CentOS下Eclipse的安装教程
  2. SQL 存储和触发器
  3. 使用buildbot实现持续集成(转载)
  4. 缺少HTML Doctype造成的样式问题
  5. css javascript 自动化压缩(保存后即自动生成压缩文件)
  6. Windows Server 2008 网管数据采集 努力做“日拱一卒“
  7. Winform: use the WebBrowser to display XML with xslt, xml, xslt 转 html 字符串
  8. Maven配置插件跳过测试代码的编译和运行
  9. 2、Web应用程序中的安全向量 -- CSRF/XSRF(跨站请求伪造)
  10. python爬虫xpath
  11. sublimeserver启动本地服务器(sublime text)
  12. android cookie持久化
  13. 4.2 Oracle Dataguard failover 操作步骤
  14. 【练习】Python第四次:实现对文件的增删改查
  15. mvc Model验证总结及常用正则表达式
  16. [2011山东ACM省赛] Mathman Bank(模拟题)
  17. java实现读取ftp服务器上的csv文件
  18. Servlet 3.0 对异步处理的支持
  19. 145.Binary Tree Postorder Traversal---二叉树后序非递归遍历
  20. Linux安装apue.3e(基于ubuntu16.0.4)

热门文章

  1. iOS - Frame 项目架构
  2. 使用window.print实现网页打印
  3. js 过滤script
  4. 1 Spring MVC 原理
  5. 在node.js中使用mongose模块
  6. Python内置的字符串处理函数整理
  7. LoarRunner11使用异常及解决方案
  8. Code Simplicity–The Science of Software Development 书摘
  9. freemarker if elseif
  10. Oracle数据库备份与恢复