• php pdo分页


     <table width="95%" border="1" cellspacing="0" cellpadding="0" align="center">
          <tr align="center" height="30px">
            <td>文章标题</td>
            <td>文章内容</td>
            <td>编辑</td>        
          </tr>    
     <?php
        
            try{
            header("content:text/html; charset:utf-8");
            include "conn/conn.php";
    
            if(@$_GET['page']!=""){
                $page=$_GET['page'];    
            }else{
                $page=1;    
            }
            if($page){
                $page_size=5;
                $query="select count(*) as total from tb_affiche";
                
                $result_acticle=$pdo->prepare($query);
                $result_acticle->execute();
                $msg_count =$result_acticle->rowCount($result_acticle,0,"total");
                $page_count=ceil($msg_count/$page_size);
                $offset=($page-1)*$page_size;
            $sql="SELECT * FROM tb_article order by now desc limit $offset,$page_size ";
            if(@$_POST['btnSea']=="查询"){
                $txtb= $_POST['txtbook'];
                $sql = "SELECT * FROM tb_article where title like '%".trim($txtb)."%' or  content like '%".trim($txtb)."%' order by now desc limit 5";
                
            }
            $result_acticle=$pdo->prepare($sql);
            $result_acticle->execute();
            
            while($res_article=$result_acticle->fetch(PDO::FETCH_ASSOC)){
                ?>
              <tr height="30px">
            <td align="center"><?php echo $res_article['title']; ?></td>
            <td>&nbsp;<?php echo $res_article['content']; ?></td>
            <td width="50px" align="center"><a href="modify.php?id='<?php echo $res_article['id']; ?>'">编辑</a></td>
            <td width="50px" align="center"><a href="delete.php?id='<?php echo $res_article['id']; ?>'">删除</a></td>
          </tr>  
                
                <?php
            }
            }
            
            }catch(Exception $ex){
                echo $ex->getMessage();    
            }
    ?>
    </table>
    <table align="center" width="600" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>页次:<?php echo $page?>/<?php echo $page_count?>页&nbsp;记录:<?php echo $msg_count?>条</td>
            <td>&nbsp;</td>
           
            <td width="40px"><a href="edit.php?page=1">首页</a></td>        
            <td width="45px"><a href="edit.php?page=<?php
            if($page==1){
                echo "1";
            }else{
                 echo $page-1;
            }         
             ?>">上一页</a></td>
            
            <td width="45px"><a href="edit.php?page=<?php 
            if($page==$page_count){
                echo $page_count;
            }else{
                echo $page+1;
            }
            ?>">下一页</a></td>
            <td width="40px"><a href="edit.php?page=<?php echo $page_count?>">尾页</a></td>
          </tr>
        </table>
  • 相关阅读:
    禁止微信内置浏览器调整字体大小
    常用EXE文件反编译工具【转】
    C++发送HTTP请求---亲测可行(转)
    Cesium简介 [转]
    WebGL可视化地球和地图引擎:Cesium.js
    HTML5 canvas图形库 RGraph【转】
    [GitHub开源]基于HTML5实现的轻量级Google Earth三维地图引擎,带你畅游世界 【转】
    OpenGL实现多层绘制(Layered Rendering) [转]
    深度剖析OpenGL ES中的多线程和多窗口渲染技术
    OOP几大原则【转】
  • 原文地址:https://www.cnblogs.com/mrcln/p/3762247.html
Copyright © 2020-2023  润新知