选择显示字体大小

一个oracle分页程序,挺实用的


 
<!doctype html public &quot;-//w3c//dtd html 3.2 final//en&quot;>
<html>
<head>
<title>paging test</title>
<meta name=&quot;generator&quot; content=&quot;textpad 4.0&quot;>
<meta name=&quot;author&quot; content=&quot;?&quot;>
<meta name=&quot;keywords&quot; content=&quot;?&quot;>
<meta name=&quot;description&quot; content=&quot;?&quot;>
</head>

<body bgcolor=&quot;#ffffff&quot; text=&quot;#000000&quot; link=&quot;#ff0000&quot; vlink=&quot;#800000&quot; alink=&quot;#ff00ff&quot; background=&quot;?&quot;>
<?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 &quot;sample_table&quot; 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.

&#36;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(&quot;oracle_sid=purk&quot;);
putenv(&quot;oracle_home=/export/oracle8i&quot;);
putenv(&quot;tns_admin=&#36;oracle_home.network/admin&quot;);
&#36;oracledbconn = ocilogon(&quot;purk&quot;,&quot;purk&quot;,&quot;lengana.world&quot;);

// this query counts the records
&#36;sql_count = &quot;select count(*) from sample_table&quot;;

// parse the sql string & execute it
&#36;row_count=ociparse(&#36;oracledbconn, &#36;sql_count);
ociexecute(&#36;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(&#36;row_count)) {
&#36;num_rows = ociresult(&#36;row_count,1);
} else {
&#36;num_rows = 0; // if no record was found
}

// free the resources that were used for this query
ocifreestatement(&#36;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(&#36;page) &#36;page == 0) {
&#36;page = 1;
}

// the start range from where the results should be printed
&#36;start_range = ((&#36;page - 1) * &#36;display_rows) + 1;

// the end range to where the results should be printed
&#36;end_range = &#36;page * &#36;display_rows;

// the main query. it consists of 3 &quot;select&quot; 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 &quot;where&quot; 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 &quot;selected&quot; assigns the new row numbers to the result
// for us to select from.

&#36;sql = &quot;select pk_id, field1, field2, field3, row_no from (select pk_id, &quot;;
&#36;sql .= &quot;field1, field2, field3, rownum row_no from (select pk_id, field1, &quot;;
&#36;sql .= &quot;field2, field3 from sample_table order by field3)) where row_no between &quot;;
&#36;sql .= &#36;start_range.&quot; and &quot;.&#36;end_range;

// start results formatting
echo &quot;<table width='95%' border='1' cellspacing='1' cellpadding='2' align='center'>&quot;;
echo &quot;<tr bgcolor='#666666'>&quot;;
echo &quot;<td><b><font color='#ffffff'>pk id</font></b></td>&quot;;
echo &quot;<td><b><font color='#ffffff'>field 1</font></b></td>&quot;;
echo &quot;<td><b><font color='#ffffff'>field 2</font></b></td>&quot;;
echo &quot;<td><b><font color='#ffffff'>field 3</font></b></td>&quot;;
echo &quot;<td><b><font color='#ffffff'>row no</font></b></td>&quot;;
echo &quot;</tr>&quot;;

if (&#36;num_rows != 0) {

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

// get number of columns for use later
&#36;num_columns = ocinumcols(&#36;rs);

while (ocifetch(&#36;rs)){
echo &quot;<tr>&quot;;
for (&#36;i = 1; &#36;i < (&#36;num_columns + 1); &#36;i++) {
&#36;column_value = ociresult(&#36;rs,&#36;i);
echo &quot;<td>&#36;column_value</td>&quot;;
}
echo &quot;</tr>&quot;;
}

} else {

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

// close the table
echo &quot;</table>&quot;;

// free resources and close connection
ocifreestatement(&#36;rs);
ocilogoff(&#36;oracledbconn);

?>
<div align=center>
<?php

// here we will print the links to the other pages

// calculating the amount of pages
if (&#36;num_rows % &#36;display_rows == 0) {
&#36;total_pages = &#36;num_rows / &#36;display_rows;
} else {
&#36;total_pages = (&#36;num_rows / &#36;display_rows) + 1;
settype(&#36;total_pages, integer); // rounding the variable
}

// if this is not the first page print a link to the previous page
if (&#36;page != 1) {
echo &quot;<a href='&quot;.&#36;php_self.&quot;?page=&quot;.(&#36;page - 1).&quot;'>previous</a>&quot;;
}

// now we can print the links to the other pages
for (&#36;i = 1; &#36;i <= &#36;total_pages; &#36;i++) {
if (&#36;page == &#36;i){
// don't print the link to the current page
echo &quot; &quot;.&#36;i;
} else {
//print the links to the other pages
echo &quot; <a href='&quot;.&#36;php_self.&quot;?page=&quot;.&#36;i.&quot;'>&quot;.&#36;i.&quot;</a>&quot;;
}
}

// if this is not the last page print a link to the next page
if (&#36;page < &#36;total_pages) {
echo &quot; <a href='&quot;.&#36;php_self.&quot;?page=&quot;.(&#36;page + 1).&quot;'>next</a>&quot;;
}

?>
</div>
<?php

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

echo &quot;<p><b>total pages: </b>&quot;.&#36;total_pages.&quot;</p>&quot;;
echo &quot;<p><b>number of records: </b>&quot;.&#36;num_rows.&quot;</p>&quot;;
echo &quot;<p><b>the sql query is:</b> &quot;.&#36;sql.&quot;</p>&quot;;

?>
</body>
</html>

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons