下面是一個簡單的PHP連接mysql數據庫進行數據分頁顯示的模版.可以按注釋說明信息進行修改,裡面的sql語句是可以自己改的. 注意分析和觀察裡面相關分頁部分的代碼的書寫和實現的方式. <?php $link = mysql_connect('localhost', 'root', '') or die('mysql database connect error'); mysql_select_db('your database') or die('the selected database is not exist'); ?> //這裡插入你的Html代碼, <?php $sql = 'select count(*) count from your_table'; $result = mysql_query($sql) or die(mysql_errno().": ".mysql_error()."\n"); $rs=mysql_fetch_object($result); $recountCount = $rs->count; $show = 20; $totalPage = ceil($recountCount/$show); $page = (isset($_GET['page']) && $_GET['page']>=0)? $_GET['page']: 0; $isLast = ($page==($totalPage-1))? true: false; $hasNoPre = ($page==0)? true: false; $hasNoNext = ($page==$totalPage-1)? true: false; $isFirst = ($page==0)? true:false; $start = $page*$show; mysql_free_result($result); ?> //這裡插入你的html代碼, <? $sql = "select * from your_table limit $start,$show"; $result = mysql_query($sql) or die(mysql_errno().": ".mysql_error()."\n"); while($rs=mysql_fetch_object($result)){ //這個循環裡的html代碼自己更具實際情況修改 echo $rs->art_id; echo "<br>"; } mysql_free_result($result); ?> <? $str = "共 $recountCount 條記錄,當前第 ".($page+1)."/$totalPage 頁 "; $str .= $isFirst? "首頁 " : "<a href=\"?page=0\">首頁</a> "; $str .= $hasNoPre? "