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 < count($pager->result); $i++)
{
$tmp = $pager->result[$i];
echo " id:".$tmp['ID']."<br>";
echo " name:".$tmp['NAME']."<br>";
echo " age:".$tmp['AGE']."<hr>"
}
// }}}
// {{{ 顯示翻頁鏈結
echo $pager->page. " / ".$pager->totalpage." 共 ".$pager->total. "條記錄 ";
if ($pager->prev != 0)
echo " <a href=$PHP_SELF?page=".$pager->prev.">上一頁</a> ";
else
echo " 上一頁 ";
if ($pager->next != 0)
echo " <a href=$PHP_SELF?page=".$pager->next.">下一頁</a> ";
else
echo " 下一頁 ";
// }}}
?>
<?@OCILogoff($conn)?>