国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

一個ORACLE分頁程序

2024-08-29 13:32:28
字體:
來源:轉載
供稿:網友

<!doctype html public "-//w3c//dtd html 3.2 final//en">
<html>
<head>
<title>paging test</title>
<meta name="generator" content="textpad 4.0">
<meta name="author" content="?">
<meta name="keywords" content="?">
<meta name="description" content="?">
</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 ([email protected])
// date: 2001-06-05
// with this example, i will explain paging of database queries where the
// result is more than the developer want to print to the page, but wish to
// split the result into seperate pages.
// the table "sample_table" accessed 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 database
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 = "select count(*) from sample_table";

// parse the sql string & execute it
$row_count=ociparse($oracledbconn, $sql_count);
ociexecute($row_count);

// from the parsed & executed query, we get the amount of records found.
// i'm not storing this result into a session variable because it allows for
// new records to be shown as it is entered by another user while the result
// is printed.
if (ocifetch($row_count)) {
$num_rows = ociresult($row_count,1);
} else {
$num_rows = 0; // if no record was found
}

// free the resources that were used 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),
// set 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 "select" statements nested into each
// other. the center query is the query you would normally use to return the
// records you want. do you ordering and "where" clauses in this statement.
// we select the rows to limit our results but because the row numbers are
// assigned to the rows before any ordering is done, lets the code print the
// result unsorted.
// the second nested "selected" assigns the new row numbers to the result
// for us to select from.

$sql = "select pk_id, field1, field2, field3, row_no from (select pk_id, ";
$sql .= "field1, field2, field3, rownum row_no from (select 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) {

// parse the sql string & execute it
$rs=ociparse($oracledbconn, $sql);
ociexecute($rs);

// get number of columns for use 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>";
}

} else {

// print a message stating that no records was found
echo "<tr><td align=center>sorry! no records was found</td></tr>";
}

// close the table
echo "</table>";

// free resources and close 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;
} else {
$total_pages = ($num_rows / $display_rows) + 1;
settype($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_self."?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;
} else {
//print the links to the other pages
echo " <a href='".$php_self."?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_self."?page=".($page + 1)."'>next</a>";
}

?>
</div>
<?php

// i'm just adding this section 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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁都县| 禄丰县| 新丰县| 宣恩县| 额尔古纳市| 都安| 安多县| 成安县| 青岛市| 渭源县| 措勤县| 泰来县| 泊头市| 临澧县| 岚皋县| 固镇县| 宁国市| 金门县| 广灵县| 八宿县| 江山市| 读书| 白朗县| 抚宁县| 含山县| 葵青区| 信丰县| 南丰县| 安仁县| 安岳县| 南昌市| 喀喇沁旗| 德江县| 左贡县| 随州市| 恩平市| 斗六市| 神农架林区| 神木县| 启东市| 建水县|