<?php
$pagesize = 3;//設置每頁顯示數目
//計算總記錄數
$rs_num = "select count(*) as id from table";
$rs_num = odbc_exec($conn_id,$rs_num);
$rs_num = odbc_result($rs_num,"id");
//計算總頁數
$pagecount = $rs_num / $pagesize;
$pagecount1 = intval($pagecount);//將總頁數取整
$compare = $pagecount - $pagecount1;
switch ($compare){
case "0":
$pagecount = $pagecount1;//總頁數
break;
default :
$pagecount1++;
$pagecount = $pagecount1;//總頁數
break;
};
if ($pagecount == 0)$pagecount++;
$fpages = $pages-1;
$bpages = $pages+1;
?>
<table>
<tr>
<td>
共<?php echo $pagecount ?>頁
<?php if($pages != 1)echo "<a href=show.php3?pages=1>";?>首頁<?php if($pages != 1)echo "</a>"; ?>
<?php if($pages != 1)echo "<a href=show.php3?pages=".$fpages.">"; ?>前頁<?php if($pages != 1)echo "</a>"; ?>
<?php if($pages != $pagecount)echo "<a href=show.php3?pages=".$bpages.">"; ?>後頁<?php if($pages != $pagecount)echo "</a>"; ?> <?php if($pages != $pagecount)echo "<a href=show.php3?pages=".$pagecount.">"; ?>
尾頁<?php if($pages != $pagecount)echo "</a>"; ?>
</td>
</tr></table>
<?php
$firstshow = ($pages-1)*$pagesize+1;//確定每頁的第一條記錄
//找出第一條記錄的記錄號
$query_string = "SELECT * FROM table Order By id DESC";
$query_string = odbc_exec($conn_id,$query_string);
odbc_fetch_into($query_string,$firstshow,&$idarea);
$idsql = $idarea[0];
//定位查找
if ($pages == $pagecount) {
$rs = "SELECT * FROM table where id <= '".$idsql."' Order By id DESC";
}else{
$rs = "SELECT Top ".$pagesize." * FROM table where id <= '".$idsql."' Order By id DESC";
};
$rs = odbc_exec($conn_id,$rs);
//顯示記錄
while(odbc_fetch_row($rs)){
};
?>
<?php
//關閉連接
odbc_close($conn_id);
?>
【本文版權歸作者與奧索網共同擁有,如需轉載,請注明作者及出處】