Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6567164
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Python/Ruby

2013-01-10 19:59:00

环境:

OS:ORACLE 10GR2

PHP5

 

  在网上到处搜索到了一个比较好的分页例子,适当做了修改.

 

$page=isset($_GET['page'])?intval($_GET['page']):1;

 

$display_rows = 5;

 

$OracleDBConn = OCILogon("hxl","hxl","hxl");

 

$sql_count = "select count(*) from scott.emp";

 

$row_count=OCIParse($OracleDBConn, $sql_count);

OCIExecute($row_count);

 

 

if (OCIFetch($row_count)) {

$num_rows = OCIResult($row_count,1);

}

else {

$num_rows = 0;

}

 

OCIFreeStatement($row_count);

 

 

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;

 

$sql = "SELECT  empno, ename, ROW_NO FROM (SELECT  ";

$sql .= "empno, ename, ROWNUM ROW_NO FROM (SELECT  ";

$sql .= "empno,ename FROM scott.emp ORDER BY empno)) WHERE ROW_NO BETWEEN ";

$sql .= $start_range." AND ".$end_range;

 

// start results formatting

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

echo "

";

 

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 "

";

for ($i = 1; $i < ($num_columns + 1); $i++) {

$column_value = OCIResult($rs,$i);

echo "

";

}

echo "

";

}

 

} else {

 

// Print a message stating that no records was found

echo "

";

}

 

// Close the table

echo "

empno ename row_no
$column_value
Sorry! No records was found
";

 

// free resources and close connection

OCIFreeStatement($rs);

OCILogoff($OracleDBConn);

 

?>

 

 

// 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 "Previous";

 

}

 

// 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 " ".$i."";

 

}

}

 

// If this is not the last page print a link to the next page

if ($page < $total_pages) {

//echo " Next";

echo " Next";

}

 

?>

 

 

// I'm just adding this section to print some of the variables for extra info

// and some debugging

 

echo "

Total pages: ".$total_pages."

";

echo "

Number of records: ".$num_rows."

";

echo "

The SQL Query is: ".$sql."

";

?>

 
运行输出如下效果:
阅读(4970) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

hzdnca2015-01-13 15:33:01

你好加关键字查询直接给值可以正常分页显示如($gjz0 = "20150101" ; $gjz1 = "20150112";$gjz2 = "广东";)什么问题都没有正常;
要是从post传值过来后给值如($gjz0 = $gjz00 ;$gjz1 = $gjz10;$gjz2 = $gjz20;)用echo $gjz0 ;echo $gjz1 ;echo $gjz2;接收值正常,查询到数据也正常,就是点下一页时就没数据了,请指点一下