if (!$conn) { echo "<h1>error - could not connect to oracle</h1>"; exit; }
/* 如果連接成功,$conn就是一個連接符。否則,腳本將結束并且輸出“could not connect to oracle”的錯誤信息 現在開始來分析并且創建你的sql語句,由無限制的查詢結果得到可以記數的記錄。 在這里的格式語句“select count(*) from table_name”相當于count(),是個sql函數將會在數據庫里執行。比由依靠php計算得到的返回結果要好。 */
$sql = "select count(*) from table_name";
$stmt = ociparse($conn, $sql); if(!$stmt) { echo "<h1>error - could not parse sql statement.</h1>"; exit; }
// now loop through the pages to create numbered links // ex. 1 2 3 4 5 next >> for ($i=1;$i<=$pages;$i++) { // check if on current page if (($offset/$limit) == ($i-1)) { // $i is equal to current page, so don display a link echo "$i "; } else { // $i is not the current page, so display a link to page $i $newoffset=$limit*($i-1); echo "<a href="$php_self?offset=$newoffset">$i</a> n"; } }
//檢查當前頁面是否為最后一頁 if (!((($offset/$limit)+1)==$pages) && $pages!=1) { // not on the last page yet, so display a next link $newoffset=$offset+$limit; echo "<a href="$php_self?offset=$newoffset">next >></a><p>n"; }