php+oracle分頁類

下面是分頁示例程序,看起來可能比較繁瑣,但其實你隻要用一下就會發現,"一切原來如此簡單" 🙂
example.php
<?php
$conn = ociplogon("test","123456","test123");
include_once "pager.inc.php";
?>
<?php
/** 分頁測試開始 */
// {{{ 初始分頁對象
$pager = new pager();
/** 將 select id,name,age from test where age>20 order by id desc 拆分 */
$sqlArr = array(conn => $conn, // 數據庫連結
fields => " id,name,age ", // 查詢主語句
table => "test", // 表名
condition => " age>20 ", // 查詢條件
order => " order by id desc " // 排序方式
);
if (!$pager->listn($sqlArr,10,$page)) // 每頁顯示10條
{
$pager->errno = 10;
die($pager->errmsg());
}
//}}}
// {{{ 數據顯示
for( $i = 0; $i result); $i++)
{
$tmp = $pager->result[$i];
echo " id:".$tmp[ID]."
";
echo " name:".$tmp[NAME]."

";
echo " age:".$tmp[AGE]."


"
}
// }}}
// {{{ 顯示翻頁鏈結
echo $pager->page. " / ".$pager->totalpage." 共 ".$pager->total. "條記錄 ";
if ($pager->prev != 0)
echo " PHP_SELF$page=".$pager->prev.">上一頁 ";
else
echo " 上一頁 ";
if ($pager->next != 0)
echo " next.">下一頁 ";
else
echo " 下一頁 ";
// }}}
?>

You May Also Like