★ 请问怎么使用PHP在Oracle里做分页!?

phpphp 2004-11-26 04:29:36
要最容易理解 和最容易使的(我是个初学者)
最好不使类:)
谢谢!!
...全文
213 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
piner 2004-11-27
OCIFetchStatement($Parse,$record,$offset,$maxline,OCI_FETCHSTATEMENT_BY_ROW)
回复
-神仙- 2004-11-27
不是和mysql差不多的吗?????
回复
phpphp 2004-11-27
adodb 是啥?连数据库的?咋使?:P
回复
黑夜路人 2004-11-26
建议用adodb或者db来做,呵呵
回复
jxyuhua 2004-11-26
<?php
//PEAR中的Pager文件,自己可以下载
include_once('Pager/Pager.php');
$products = getResult($keywords);//将要显示的数据,数组类型
$params = array(
'mode' => 'Jumping',
'perPage' => 5,
'delta' => 5,
'itemData' => $products,
'linkClass' => 'pageResults',
);
$pager = & Pager::factory($params);
$page_data = $pager->getPageData();
$links = $pager->getLinks();
$selectBox = $pager->getPerPageSelectBox();
$pageOffset = $pager->getOffsetByPageId();
for ($i=$pageOffset[0]-1; $i<$pageOffset[1]; $i++) {
//显示
}
echo "Result Pages:  " .$links['all'];
$display = "Displaying %d to %d (of %d products)";
printf($display, $pageOffset[0], $pageOffset[1], $pager->numItems());
回复
hahawen 2004-11-26
楼上的写的对,oricle的分页要通过子查询来实现, 所以不建议自己写,建议用adodb来处理数据库问题
回复
erldy 2004-11-26
PHP+ORACLE 分页代码:
//分页程序开始
$display_rows = 10;
$sql = "SELECT COUNT(*) FROM $tbl where msg_sort_id=$sid";
$stmt = Query($c245,$sql);

if (OCIFetch($stmt)) {
$num_rows = OCIResult($stmt,1);
} else {
$num_rows = 0;
}

OCIFreeStatement($stmt);
$page = $_GET['page'];
if (empty($page) || $page == 0) {
$page = 1;
}
$start_range = (($page - 1) * $display_rows) + 1;
$end_range = $page * $display_rows;
$sql = "SELECT msg_id,msg_content,msg_sort_id,msg_sort_name,msg_hide,msg_commend,msg_hits,ROW_NO FROM (SELECT msg_id,";
$sql .= "msg_content,msg_sort_id,msg_sort_name,msg_hide,msg_commend,msg_hits,ROWNUM ROW_NO FROM (SELECT msg_id,msg_content,";
$sql .= "msg_sort_id,msg_sort_name,msg_hide,msg_commend,msg_hits FROM $tbl where msg_sort_id=$sid ORDER BY msg_id desc)) WHERE ROW_NO BETWEEN ";
$sql .= $start_range." AND ".$end_range;

//显示数据

if ($num_rows != 0) {
$stmt = Query($c245,$sql);
while(OCIFetchInto($stmt, &$ary)) {
……
}
}

//显示导航条
if ($num_rows % $display_rows == 0) {
$total_pages = $num_rows / $display_rows;
} else {
$total_pages = ($num_rows / $display_rows) + 1;
settype($total_pages, integer);
}

if ($page != 1) {
echo "<a href='".$PHP_SELF."?page=".($page - 1)."&sid=".$sid."'>上一页</a>";
}

for ($i = 1; $i <= $total_pages; $i++) {
if ($page == $i){
echo " ".$i;
} else {
echo " <a href='".$PHP_SELF."?page=".$i."&sid=".$sid."'>".$i."</a>";
}
}

if ($page < $total_pages) {
echo " <a href='".$PHP_SELF."?page=".($page + 1)."&sid=".$sid."'>下一页</a>";
}
echo "  总页数: <b><font color=red>".$total_pages."</font></b>    总记录数: <b><font color=red>".$num_rows."</font></b>";
//结束分页


用三层子查询来实现,效率很高!
回复
leyan728 2004-11-26
/**
* @函数功能:显示系统用户
* @函数作者:乐言 www.leyan.net
* @函数参数: $setid -> 起始记录数
* $list_num -> 显示记录条数
* $swjg_dm -> 税务机关代码
* @函数返回:
* @修改时间:2004-11-22
*/
function list_user($setid,$list_num,$swjg_dm){
require ("include/config.php");
if(@$conn=OCILogon("$dbuser","$dbpasswd","$dbname")):
// 计算起始记录数
if (empty($setid)):
$setid = 0;
endif;
$setidend=1+$setid+$list_num;
$list_user_sql="select * from (select rownum rn,ry_dm,ry_mc,ry_mm,ry_gwzz,ry_qx,swjg_dm,zg_dm from ".$user_table." where rownum<".$setidend." and swjg_dm=".$swjg_dm.") where rn>".$setid." and swjg_dm=".$swjg_dm." ORDER BY ry_qx DESC";
$list_user=OCIParse($conn,$list_user_sql);
OCIDefineByName($list_user,"RY_DM",$ry_dm);
OCIDefineByName($list_user,"RY_MC",$ry_mc);
OCIDefineByName($list_user,"RY_QX",$ry_qx);
OCIDefineByName($list_user,"ZG_DM",$zg_dm);
OCIExecute($list_user);
$bgcolor=true;
while(OCIFetch($list_user)){
if ($bgcolor):
echo "<tr bgcolor='#EFEFEF' align=center>";
else:
echo "<tr bgcolor='#FFFFFF' align=center>";
endif;
echo "<td>".$ry_dm."</td><td>".$ry_mc."</td>";
echo "<td>";
if ($ry_qx==1):
echo "一般用户";
elseif ($ry_qx==2):
echo "抽查人";
else:
echo "系统管理员";
endif;
echo "</td><td>";
if ($zg_dm!="0"):
echo ry_info($zg_dm,"ry_mc");
endif;

echo "</td><td><a href=\"?action=userinfo&ry_dm=".$ry_dm."\" class=menu>编辑</a>|<a href=\"javascript:Delete('".$ry_dm."')\" class=menu>删除</a></td></tr>";
$bgcolor=!$bgcolor;
}
OCILogoff($conn);
else:
OCILogoff($conn);
echo "系统忙,请稍候访问!";
echo "系统将2秒中后返回上一页!";
echo "<META HTTP-EQUIV=REFRESH CONTENT='2;URL=javascript:history.back(1)'> ";
endif;
} // 结束


/**
* @函数功能:用户分页显示
* @函数作者:乐言 www.leyan.net
* @函数参数: $table_name -> 分页表格名称
* $query_condition -> 查询的条件语句
* $list_num -> 显示记录条数
* $list_page_num -> 每列显示页数
* $setid -> 数据起始id
* @函数返回:
* @修改时间:
*/
function list_page($table_name,$query_condition,$list_num,$list_page_num,$setid){
require ("include/config.php");
if(@$conn=OCILogon("$dbuser","$dbpasswd","$dbname")):
if ($query_condition==""):
$query_sql="select count(1) as rcnt from ".$table_name."";
else:
$query_sql="select count(1) as rcnt from ".$table_name." where ".$query_condition."";
endif;
$list_page=OCIParse($conn,$query_sql);
OCIDefineByName($list_page,"RCNT",$rcnt);
OCIExecute($list_page);
OCIFetch($list_page);
// 计算页数
$pages = ceil($rcnt/$list_num);
if ($setid > 0):
$setpage1 = ceil($setid/$list_num);
$setpage = ceil(($setpage1+1)/$list_page_num);
else:
$setpage = 1;
endif;
if ($pages > $list_page_num):
$pagenum = $list_page_num;
else:
$pagenum = $pages;
endif;
$issetid = ceil(($setid+1)/$list_num);
$issetpage = $issetid % $list_page_num;
// 第一页
if ($setpage > 1):
echo "<a title='第一页' href='?setpage=1&setid=0' class=write>[第1页]</a>\n";
endif;
// 上一列
if ($setpage > 1):
$lastpage = $setpage-1;
$lastsetid = ($setpage-2)*$list_page_num*$list_num;
echo "<a title='上一列' href='?setpage=".$lastpage."&setid=".$lastsetid."' class=write>[<<]</a>\n";
endif;
// 上一页
if ($setid > 0):
if ($issetpage == 1):
$newsetpage = $setpage-1;
else:
$newsetpage = $setpage;
endif;
$presetid = $setid-$list_num;
echo "<a title='上一页' href='?setpage=".$newsetpage."&setid=".$presetid."' class=write>[<]</a>\n";
endif;
// 列出页
$i1 = ($setpage-1)*$list_page_num;
for ($i=$i1; $i<($i1+$pagenum) && $i<$pages; $i++)
{
$newsetid=$list_num*$i;
if (($setid/$list_num) == $i):
echo "<b><font color=red>[第".($i+1)."页]</font></b> \n";
else:
echo "<a href='?setpage=".$setpage."&setid=".$newsetid."' class=write>[第".($i+1)."页]</a>\n";
endif;
}
// 下一页
if ($pages!=0 && ($setid/$list_num+1)!=$pages && ($setid/$list_num+1)<=$pages||$setid==1):
if ($list_page_num-$issetpage == 0 || $issetpage == 0):
$newsetpage = $setpage+1;
else:
$newsetpage = $setpage;
endif;
$newsetid = $setid+$list_num;
echo "<a title='下一页' href='?setpage=".$newsetpage."&setid=".$newsetid."' class=write>[>]</a>\n";
endif;
// 下一列
if ($pages!=0 && $pages>$list_page_num && $setpage<$page):
$nextpage = $setpage+1;
$nextsetid = $setpage*$list_page_num*$list_num;
echo "<a title='下一列' href='?setpage=".$nextpage."&setid=".$nextsetid."' class=write>[>>]</a>\n";
endif;
// 最后一页
if ($pages>$list_page_num && $setpage<$page):
$lastpage = $list_num*($pages-1);
echo "<a title='最后一页' href='?setpage=".$page."&setid=".$lastpage."' class=write>[第".$pages."页]</a>\n";
endif;
OCILogoff($conn);
else:
error("系统繁忙,请稍后再试!");
echo "<META HTTP-EQUIV=REFRESH CONTENT='0;URL=javascript:history.back(1)'> ";
exit;
endif;
} // 结束

----------------------------------------
楼主可以看看吧,这是我写的分页函数.起始最重要的就是那句sql语句!
回复
uGain 2004-11-26
建议你使用adodb.
回复
相关推荐
发帖
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2004-11-26 04:29
社区公告
暂无公告