首页 > 代码库 > php pdo分页
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> <?php echo $res_article[‘content‘]; ?></td> <td width="50px" align="center"><a href="http://www.mamicode.com/modify.php?id=‘<?php echo $res_article[‘id‘]; ?>‘">编辑</a></td> <td width="50px" align="center"><a href="http://www.mamicode.com/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?>页 记录:<?php echo $msg_count?>条</td> <td> </td> <td width="40px"><a href="http://www.mamicode.com/edit.php?page=1">首页</a></td> <td width="45px"><a href="http://www.mamicode.com/edit.php?page=<?php if($page==1){ echo "1"; }else{ echo $page-1; } ?>">上一页</a></td> <td width="45px"><a href="http://www.mamicode.com/edit.php?page=<?php if($page==$page_count){ echo $page_count; }else{ echo $page+1; } ?>">下一页</a></td> <td width="40px"><a href="http://www.mamicode.com/edit.php?page=<?php echo $page_count?>">尾页</a></td> </tr> </table>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。