php pdo分頁

來源:互聯網
上載者:User

標籤:des   c   style   class   blog   code   

 <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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.