<!doctype html public “-//w3c//dtd html 3.2 final//en”>
<html>
<head>
<title>paging test</title>
<meta name=儿童节祝福语大全简短221;generator” content=”textpad 4.0″>
<meta name=”author” content=”?”>
<meta name=”keywords” content=”?”>
<meta name=”description” content=”?&火车票电话订票几点开始#8221;>
</head>
<body bgcolor=”#ffffff” text=”#000000″ link=”#ff0000″ vlink=”#800000″ alink=”#ff00ff” background=”?”>
<?php
// how to split the result into pages, like ‘limits’ in mysql?
// ===========================================================
// tutorial by neil craig (neilc@netactive.co.za)
// date: 2001-06-05
// with this example, i will explain paging of databa queries where the
// result is more than the developer want to print to the page, but wish to
// split the result into perate pages.
// the table “sample_table” accesd in this tutorial has 4 fields:
// pk_id, field1, field2 and field3. the types don’t matter but you should
// define a primary key on the pk_id field.
$display_rows = 5;// the rows that should be display at a time. you can
// modify this if you like.
// connect to the oracle databa
putenv(“oracle_sid=purk”);
putenv(“oracle_home=/export/oracle8i”);
putenv(“tns_admin=$oracle_home/network/admin”);
$oracledbconn = ocilogon(“purk”,”purk”,”lengana.world”);
// this query counts the records
$sql_count = “lect count(*) from sample_table”;
// par the sql string & execute it
$row_count=ocipar($oracledbconn, $sql_count);
ociexecute($row_count);
// from the pard & executed query, we get the amount of reco乙醇是什么rds found.
// i’m not storing this result into a ssion variable becau it allows for
// new records to be shown as it is entered by another ur while the result
// is printed.
if (ocifetch($row_count)) {
$num_rows = ociresult($row_count,1);
} el {
$num_rows = 0;// if no record was found
}
// free the resources that were ud for this query
ocifreestatement($row_count);
// we need to prepare the query that will print the results as a page. i will
// explain the query to you in detail.
// if no page was specified in the url (ex. http://mysite.com/result.php?page=2),
// t it to page 1.
if (empty($page) || $page == 0) {
$page = 1;
}
// the start range from where the results should be printed
$start_range = (($page – 1) * $display_rows) + 1;
// the end range to where the results should be printed
$end_range = $page * $display_rows;
// the main query. it consists of 3 “lect” statements nested into each
// other. the center query is the query you would normally u to return the
// records you want. do you ordering and “where” claus in this statement.
// we lect the rows to limit our results but becau the row numbers are
// assigned to the rows before any ordering is done, lets the code print the
// result unsorted.
// the cond nested “lected” assigns the new row numbers to the result
// for us to lect from.
$sql = 鱼我所欲也通假字220;lect pk_id, field1, field2, field3, row_no from (lect pk_id, “;
$sql .= “field1, field2, field3, rownum row_no from (lect pk_id, field1, “;
$sql .= “field2, field3 from sample_table order by field3)) where row_no between “;
$sql .= $start_range.” and “.$end_range;
// start results formatting
echo “<table width=’95%’ border=’1′ cellspacing=’1′ cellpadding=’2′ align=’center’>”;
echo “<tr bgcolor=’#666666′>”;
echo “<td><b><font color=’#ffffff’>pk id</font></b></td>”;
echo “<td><b><font color=’#ffffff’>field 1</font></b></td>”;
echo “<td><b><font color=’#ffffff’>field 2</font></b></td>”;
echo “<td><b><font color=’#ffffff’>field 3</font></b></td>”;
echo “<td><b><font color=’#ffffff’>row no</font></b></td>”;
echo “</tr>”;
if ($num_rows != 0) {
// par the sql string & execute it
$rs=ocipar($oracledbconn, $sql);
ociexecute($rs);
// get number of columns for u later
$num_columns = ocinumcols($rs);
while (ocifetch($rs)){
echo “<tr>”;
for ($i = 1; $i < ($num_columns + 1); $i++) {
$column_value = ociresult($rs,$i);
echo “<td>$column_value</td>”;
}
echo “</tr>”;
}
} el {
// print a message stating that no records was found
echo “<tr><td align=center>sorry! no records was found</td></tr>”爱我中华 合唱;;
}
// clo the table
echo “</table>”;
// free resources and clo connection
ocifreestatement($rs);
ocilogoff($oracledbconn);
?>
<div align=center>
<?php
// here we will print the links to the other pages
// calculating the amount of pages
if ($num_rows % $display_rows == 0) {
$total_pages = $num_rows / $display_rows;
} el {
$total_pages = ($num_rows / $display_rows) + 1;
ttype($total_pages, integer); // rounding the variable
}
// if this is not the first page print a link to the previous page
if ($page != 1) {
echo “<a href='”.$php_lf.”?page=”.($page – 1).”‘>previous</a>”;
}
// now we can print the links to the other pages
for ($i = 1; $i <= $total_pages;$i++) {
if ($page == $i){
// don’t print the link to the current page
echo ” “.$i;
} el {
//print the links to the other pages
echo ” <a href='”.$php_lf.”?page=”.$i.”‘>”.$i.”</a>”;
}
}
// if this is not the last page print a link to the next page
if ($page < $total_pages) {
echo ” <a href='”.$php_lf.”?page=”.($page + 1).”‘>next</a>”;
}
?>
</div>
<?php
// i’m just adding this ction to print some of the variables for extra info
// and some debugging
echo “<p><b>total pages: </b>”.$total_pages.”</p>”;
echo “<p><b>number of records: </b>”.$num_rows.”</p>”;
echo “<p><b>the sql query is:</b> “.$sql.”</p>”;
?>
</body>
</html>
本文发布于:2023-04-06 06:50:49,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/c9b5e7b7be247c5fc7d551b4355be370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:一个ORACLE分页程序,挺实用的..doc
本文 PDF 下载地址:一个ORACLE分页程序,挺实用的..pdf
留言与评论(共有 0 条评论) |