php 簡易分頁代碼

來源:互聯網
上載者:User

標籤:php 分頁 代碼

使用php製作了一個部落格之後,對於分頁代碼著實讓我這個零基礎的人費了一番老勁,終於研究了一天一夜之後,勉強寫了一段簡易代碼,勉強可以使用。此為第一個版本,未來會更新到用類的方式進行分頁。加油~

<?php //設定每頁顯示的文章數$pagesize=5;//確定頁數P的參數@$p=$_GET[‘p‘]?$_GET[‘p‘]:1;//資料指標$offset = ($p-1)*$pagesize;//查詢本頁顯示的資料  $query = "select * from `arts` order by id DESC limit $offset,$pagesize";  //查詢資料  $res=mysql_query($query);  while ($row=mysql_fetch_array($res)){ //迴圈開始?><div class="nav_new">  <ul>    <li><a href="view.php?id=<?php echo $row[‘id‘]?>" target="_blank"><?php echo $row[‘title‘]?></a></li>  </ul>  </div><?php   }?>    <div style="width:990px; height:15px; margin-top:15px;text-align:right;"><?php //計算留言總數$count_result=mysql_query("select count(*) as count from arts");$count_array=mysql_fetch_array($count_result);//計算總頁數$pagenum=ceil($count_array[‘count‘]/$pagesize);//輸出各個頁數和連結if($pagenum>1){    for($i=1;$i<=$pagenum;$i++){        if($i==$p){            echo ‘[‘,$i,‘]‘;        }else{            echo "&nbsp;".‘<a href="index.php?p=‘,$i,‘">‘,$i,‘&nbsp;</a>‘;        }    }}echo "&nbsp;&nbsp;".‘共‘,$count_array[‘count‘],‘篇文章‘;?>        </div>


本文出自 “7C” 部落格,轉載請與作者聯絡!

php 簡易分頁代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.