<!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 (neilc@netactive.co.za)
// 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>

一个ORACLE分页程序,挺实用的.的更多相关文章

  1. ios – UIScrollView的平滑自定义分页

    我在UIScrollView中有两个(可能更多)视图,并希望使用分页.当我尝试使用UIScrollView的默认分页选项时出现问题,因为视图具有不同的宽度,无法正确分页.所以我已经实现了一个有效的自定义分页代码.但是,当滚动较慢时,它不会按预期运行.(它回到没有动画的原始位置.)以下是我目前通过uiscrollviewdelegate进行自定义分页的方法我想要的是:是)我有的:解决方法尝试下面的自

  2. ios – 使用子视图控制器分页滚动视图

    使用分页实现水平滚动视图的最佳做法是什么,每页有一个视图控制器?由于iOS5具有用于视图控制器容器/包含的API,因此PageControl示例仍然是实现此功能的最佳方式吗?

  3. 可可触摸 – 启用预览和分页的UICollectionView

    在AppStore中显示搜索结果时,我正在尝试模仿苹果公司的功能.(参考:http://searchengineland.com/apple-app-search-shows-only-one-result-at-a-time-133818)它显示像卡中的详细应用程序信息,并且它被分页.当中间的一个活动卡片和滚动视图的分页行为仍然完整时,我被困在如何使上一张和第二张卡片显示.我已经尝试使用UICo

  4. ios – 蓝牙LE,scanForPeripheralsWithServices在后台增加速度

    我在iPhone5S上使用蓝牙LE,我做了以下工作:>我有一个蓝牙外设,我配置它在所有三个蓝牙广告频道(37,38和39)上宣布每20秒.>我已经配置了我的应用程序与UIBacgroundModes=蓝牙中央在Info.plist>我已经启动了一个scanForperipheralsWithServices,如下所示码:目前的状态是:>在前台模式下,当我启动外围设备时(一秒钟内),应用程序会迅速收

  5. IOS蓝牙LE:无法使用存储的配对数据进行连接

    花了几个小时搜索网路,没有运气这里是我的问题:>如何使用我手机中存储的配对数据将iPhone应用程序从我的iPhone应用程序连接到蓝牙LE设备?我错过了什么吗?>这可能不是IOS的问题,因为如果配对数据存在于连接设备的手机中,会自动使用?更新2013-10-27我已经发现,如果配对存在,那么在发现特性之后,您无法通过配对认证来读取受保护的特性.没有保护特性的问题!

  6. ios – 启用了内容插入的UIScrollView分页工作很奇怪

    我创建了具有内容插入的UIScrollView.第一次,scrollView.contentOffset.x为-160.0但是奇怪的问题是当我点击scrollView(黄色区域)时,内容偏移x值将重置为0并显示为这样.我尝试过几次,但是点击滚动视图会将内容偏移量重置为0.我该如何防止这种情况?解决方法UIScrollView分页通过滚动与scrollView宽度相同的页面(在您的情况下为480个宽

  7. UIKit框架-高级控件Swift版本: 10.UIWebView方法/属性详解

    前面我们已经讲解完了UINavigationController的一些常用属性以及方法,现在让我们来看看一个关于网络的UIWebView.1.UIWebView的常用属性常用类型2.UIWebView的代理方法3.代码示范首先我们要使用storyBoard布局界面关联控件遵守代理协议自定义UIWebVIew实现代理方法在ViewDidLoad方法中实现PS:UIWebView继承与UIView,并

  8. swift+storyboard+UIImageview入门

    更新记录:该Storyboard教程由CarolineBegbie更新iOS8和Swift相关内容。Storyboard是最先在iOS5引入的一项振奋人心的特性,大幅缩减构建App用户界面所需的时间。要介绍Storyboard是什么,我打算从这张图讲起。这就是使用Storyboard的力量。Storyboard通过新的原型表项和静态表项特性,让处理表视图的工作更加轻松。Storyboard使自动布局更易用。接下来我们看一下Storyboard,点击项目浏览器中的Main.storyboard就可以在Int

  9. 使用RxSwift进行分页API调用

    如何实现这一点的任何建议将非常感谢…

  10. Angular2 PrimeNG分页模块学习

    这篇文章主要为大家详细介绍了Angular2 PrimeNG分页模块学习教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

随机推荐

  1. PHP个人网站架设连环讲(一)

    先下一个OmnihttpdProffesinalV2.06,装上就有PHP4beta3可以用了。PHP4给我们带来一个简单的方法,就是使用SESSION(会话)级变量。但是如果不是PHP4又该怎么办?我们可以假设某人在15分钟以内对你的网页的请求都不属于一个新的人次,这样你可以做个计数的过程存在INC里,在每一个页面引用,访客第一次进入时将访问时间送到cookie里。以后每个页面被访问时都检查cookie上次访问时间值。

  2. PHP函数学习之PHP函数点评

    PHP函数使用说明,应用举例,精简点评,希望对您学习php有所帮助

  3. ecshop2.7.3 在php5.4下的各种错误问题处理

    将方法内的函数,分拆为2个部分。这个和gd库没有一点关系,是ecshop程序的问题。会出现这种问题,不外乎就是当前会员的session或者程序对cookie的处理存在漏洞。进过本地测试,includes\modules\integrates\ecshop.php这个整合自身会员的类中没有重写integrate.php中的check_cookie()方法导致,验证cookie时返回的username为空,丢失了登录状态,在ecshop.php中重写了此方法就可以了。把他加到ecshop.php的最后面去就可

  4. NT IIS下用ODBC连接数据库

    $connection=intodbc_connect建立数据库连接,$query_string="查询记录的条件"如:$query_string="select*fromtable"用$cur=intodbc_exec检索数据库,将记录集放入$cur变量中。再用while{$var1=odbc_result;$var2=odbc_result;...}读取odbc_exec()返回的数据集$cur。最后是odbc_close关闭数据库的连接。odbc_result()函数是取当前记录的指定字段值。

  5. PHP使用JpGraph绘制折线图操作示例【附源码下载】

    这篇文章主要介绍了PHP使用JpGraph绘制折线图操作,结合实例形式分析了php使用JpGraph的相关操作技巧与注意事项,并附带源码供读者下载参考,需要的朋友可以参考下

  6. zen_cart实现支付前生成订单的方法

    这篇文章主要介绍了zen_cart实现支付前生成订单的方法,结合实例形式详细分析了zen_cart支付前生成订单的具体步骤与相关实现技巧,需要的朋友可以参考下

  7. Thinkphp5框架实现获取数据库数据到视图的方法

    这篇文章主要介绍了Thinkphp5框架实现获取数据库数据到视图的方法,涉及thinkPHP5数据库配置、读取、模型操作及视图调用相关操作技巧,需要的朋友可以参考下

  8. PHP+jquery+CSS制作头像登录窗(仿QQ登陆)

    本篇文章介绍了PHP结合jQ和CSS制作头像登录窗(仿QQ登陆),实现了类似QQ的登陆界面,很有参考价值,有需要的朋友可以了解一下。

  9. 基于win2003虚拟机中apache服务器的访问

    下面小编就为大家带来一篇基于win2003虚拟机中apache服务器的访问。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  10. Yii2中组件的注册与创建方法

    这篇文章主要介绍了Yii2之组件的注册与创建的实现方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下

返回
顶部