仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1021|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网站制作之一个ORACLE分页法式,挺适用的.

[复制链接]
老尸 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:07:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
PHP于1994年由Rasmus Lerdorf创建,刚刚开始是Rasmus Lerdorf为了要维护个人网页而制作的一个简单的用Perl语言编写的程序。   <!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>
熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作完整的网页,对元素属性达到熟悉程度
蒙在股里 该用户已被删除
沙发
发表于 2015-2-4 08:57:35 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
再现理想 该用户已被删除
板凳
发表于 2015-2-6 20:04:15 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
第二个灵魂 该用户已被删除
地板
发表于 2015-2-18 12:12:00 | 只看该作者
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81
小妖女 该用户已被删除
5#
发表于 2015-3-6 06:31:53 | 只看该作者
本文当是我的笔记啦,遇到的问题随时填充
飘灵儿 该用户已被删除
6#
发表于 2015-3-6 20:54:13 | 只看该作者
实践是检验自己会不会的真理。
若相依 该用户已被删除
7#
发表于 2015-3-13 09:17:56 | 只看该作者
有时候汉字的空格也能导致页面出错,所以在写代码的时候,要输入空格最好用引文模式。
海妖 该用户已被删除
8#
发表于 2015-3-17 09:22:08 | 只看该作者
如果你可以写完像留言板这样的程序,那么你可以去一些别人的代码了,
admin 该用户已被删除
9#
发表于 2015-3-24 05:53:49 | 只看该作者
本文当是我的笔记啦,遇到的问题随时填充
10#
发表于 2015-3-25 02:33:40 | 只看该作者
对于初学者来说不推荐去拿钱买的。当然如果一个网站你经常去用,而且里面的资料也比较有用,最好还是买个会员比较好,毕竟那些也是别人的工作成果。
金色的骷髅 该用户已被删除
11#
发表于 2015-3-27 05:10:29 | 只看该作者
基础有没有对学习php没有太大区别,关键是兴趣。
愤怒的大鸟 该用户已被删除
12#
发表于 2015-4-3 04:30:51 | 只看该作者
本文当是我的笔记啦,遇到的问题随时填充
若天明 该用户已被删除
13#
发表于 2015-4-3 22:26:31 | 只看该作者
找到的的资料很多都是在论坛里的,需要注册,所以我一般没到一个论坛都注册一个id,所有的id都注册成一样的,这样下次再进来的时候就不用重复注册啦。当然有些论坛的某些资料是需要的付费的。
谁可相欹 该用户已被删除
14#
发表于 2015-4-4 08:20:05 | 只看该作者
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
透明 该用户已被删除
15#
发表于 2015-4-16 15:21:49 | 只看该作者
微软最近出的新字体“微软雅黑”,虽然是挺漂亮的,不过firefox  支持的不是很好,所以能少用还是少用的好。
飘飘悠悠 该用户已被删除
16#
发表于 2015-4-17 13:02:23 | 只看该作者
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
山那边是海 该用户已被删除
17#
发表于 2015-4-21 09:15:45 | 只看该作者
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
小女巫 该用户已被删除
18#
发表于 2015-4-24 06:52:58 | 只看该作者
因为blog这样的可以让你接触更多要学的知识,可以接触用到类,模板,js ,ajax
小魔女 该用户已被删除
19#
发表于 2015-4-26 05:11:38 | 只看该作者
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
老尸 该用户已被删除
20#
 楼主| 发表于 2015-4-28 04:48:52 | 只看该作者
Ps:以上纯属原创,如有雷同,纯属巧合
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-15 11:44

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表