用php+oracle實現分頁的樣本程式

來源:互聯網
上載者:User
oracle|程式|分頁|樣本 <html>
<body>
<?
include "/maya/inc/dbconn.php";
$sql="select max(rownum) from xqhtest where id<50";
$stmt=ociparse($gConn,$sql);
ociexecute($stmt);
ocifetch($stmt);
$rowcount=ociresult($stmt,1);
ocifreestatement($stmt);
echo("共有".$rowcount."條記錄<br>\n");
$recordperpage=15; //每頁顯示多少條記錄
$pages=ceil($rowcount/$recordperpage);  //總頁數
echo("共有".$pages."頁<br>\n");

?>
<table border=0><tr><td>id</td><td>name</td></tr>
<?

//判斷位移量參數是否傳遞給了指令碼,如果沒有就使用預設值0

if (empty($offset))
{
    $offset=1;
}
$currentpage=ceil($offset/$recordperpage); //顯示當前頁
echo("當前頁:".$currentpage."<br>\n");
$endset=$offset+$recordperpage;

$stmt2=ociparse($gConn,"SELECT rownum,id,name FROM xqhtest WHERE id<50 and rownum<".$endset." minus select rownum,id,name from xqhtest where id<50 and rownum<".$offset);
//echo "SELECT id,name FROM xqhtest WHERE rownum<".$endset." minus select id,name from xqhtest where rownum<".$offset."<br>\n";
ociexecute($stmt2);
//可以是任何sql語句,但select後面一定要有rownum,這是oracle特有的!
while (ocifetch($stmt2))

{
echo("<tr><td>".ociresult($stmt2,"ID")."</td><td>".ociresult($stmt2,"NAME")."</td></tr>\n");

   //換成你用於顯示返回記錄的代碼
}
//要寫出到所有頁面的連結
print "</table><br><br>";


for ($i=1; $i <= $pages; $i++)
{
  $newoffset=($recordperpage*($i-1))+1;
  print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
print "<br>";

$nextoffset=$recordperpage*$currentpage+1;
$prevoffset=$recordperpage*($currentpage-2)+1;
//判斷是否需要上一頁串連
if (($currentpage>1) && ($currentpage<=$pages))
{
print "<a href=\"$PHP_SELF?offset=$prevoffset\">上一頁</a> \n";
}

//判斷是否需要下一頁串連
if (($pages!=0) && ($currentpage<$pages))
{
  print "<a href=\"$PHP_SELF?offset=$nextoffset\">下一頁</a> \n";
}

ocifreestatement($stmt2);
ocilogoff($gConn);
?>
</body>
</html> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.