|
$pagesize = 3;//設(shè)置每頁(yè)顯示數(shù)目
//計(jì)算總記錄數(shù)
$rs_num = "select count(*) as id from table";
$rs_num = odbc_exec($conn_id,$rs_num);
$rs_num = odbc_result($rs_num,"id");
//計(jì)算總頁(yè)數(shù)
$pagecount = $rs_num / $pagesize;
$pagecount1 = intval($pagecount);//將總頁(yè)數(shù)取整
$compare = $pagecount - $pagecount1;
switch ($compare){
case "0":
$pagecount = $pagecount1;//總頁(yè)數(shù)
break;
default :
$pagecount1++;
$pagecount = $pagecount1;//總頁(yè)數(shù)
break;
};
if ($pagecount == 0)$pagecount++;
$fpages = $pages-1;
$bpages = $pages+1;
?>
<table>
<tr>
<td>
共<?php echo $pagecount ?>頁(yè)
<?php if($pages != 1)echo "<a href=show.php3?pages=1>";?>首頁(yè)<?php if($pages != 1)echo "</a>"; ?>
<?php if($pages != 1)echo "<a href=show.php3?pages=".$fpages.">"; ?>前頁(yè)<?php if($pages != 1)echo "</a>"; ?>
<?php if($pages != $pagecount)echo "<a href=show.php3?pages=".$bpages.">"; ?>后頁(yè)<?php if($pages != $pagecount)echo "</a>"; ?> <?php if($pages != $pagecount)echo "<a href=show.php3?pages=".$pagecount.">"; ?>
尾頁(yè)<?php if($pages != $pagecount)echo "</a>"; ?>
</td>
</tr></table>
<?php
$firstshow = ($pages-1)*$pagesize+1;//確定每頁(yè)的第一條記錄
//找出第一條記錄的記錄號(hào)
$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
//關(guān)閉連接
odbc_close($conn_id);
?>
【本文版權(quán)歸作者與奧索網(wǎng)共同擁有,如需轉(zhuǎn)載,請(qǐng)注明作者及出處】
php技術(shù):用ODBC的分頁(yè)顯示,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。