一个ORACLE分页程序,javascript调节和测量检验原理

2019-10-03 15:55栏目:网络时代
TAG:

<!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.

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

 图片 1

// The end range to where the results should be printed
$end_range = $page * $display_rows;

图片 2 javascript调试原理(一)中讲了javascript的调试原理,本单给出一个javascript调试的客户端模拟实现: 

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

Java代码 

$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;

只要把其中的alert换成同步的ajax请求,一可以实现每句执行时把当前的行号,context等 信息传给调试服务器。 

?>
</div>
<?php

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
  2. <HTML>  
  3. <HEAD>  
  4. <TITLE> New Document </TITLE>  
  5. <META NAME="Generator" CONTENT="EditPlus">  
  6. <META NAME="Author" CONTENT="">  
  7. <META NAME="Keywords" CONTENT="">  
  8. <META NAME="Description" CONTENT="">  
  9. </HEAD>  
  10.   
  11. <BODY>  
  12. <textarea id="jsstr" readonly style="width:400px;height:200px">  
  13. function test(){  
  14.     var a = test1();  
  15.     var b = test2();  
  16.     var c = "result is " + a + b;  
  17.     alert(c);  
  18. }  
  19. function test1(){  
  20.     return "test1-->abc";  
  21. }  
  22. function test2(){  
  23.     return "test2-->abc";  
  24. }  
  25. test();  
  26. </textarea>  
  27. <div id="result">  
  28.       
  29. </div>  
  30. <script>  
  31. var debugStr = "";  
  32. function jsdebug(resource,line,evalFunc){  
  33.     var lines = debugStr.split("n");  
  34.     var jsLine = lines[line-1];  
  35.     lines[line-1] = "当前行:--->" + jsLine;  
  36.     var arr = [  
  37.         "调试代码:",  
  38.         lines.join("n")  
  39.     ];  
  40.     var result = document.getElementById("result");  
  41.     result.innerHTML = result.innerHTML + "<br>执行到第" + line + "行: -->" + jsLine;  
  42.     alert(arr.join("n"));  
  43.   
  44. }  
  45. function debug(str){  
  46.     var lines = str.split("n");  
  47.     debugStr = str;  
  48.     var codes = [];  
  49.     for(var i=0;i<lines.length;i++){  
  50.         codes[i] = "jsdebug('test'," + (i+1) + ",function(text){return eval(text)});" + lines[i];  
  51.     }  
  52.     eval(codes.join('n'));  
  53. }  
  54. debug(document.getElementById('jsstr').value);  
  55. </script>  
  56. </BODY>  
  57. </HTML>  

// 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.

Javascript Debug Toolkit的客户端原理是在这个基础上的,下一篇将展开讲一下这种原理会遇到的问题及解决方法。

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<?php

    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>";
    }

?>
<div align=center>
<?php

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

// We need to prepare the query that will print the results as a page. I will
// explain the query to you in detail.

$display_rows = 5;     // The rows that should be display at a time. You can
                       // modify this if you like.

    // Parse the SQL string & execute it
    $rs=OCIParse($OracleDBConn, $sql);       
    OCIExecute($rs);

<!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>

// free resources and close connection
OCIFreeStatement($rs);
OCILogoff($OracleDBConn);

您可能感兴趣的文章:

  • Oracle中使用Rownum分页详细例子
  • java调用oracle分页存储过程示例
  • oracle分页存储过程 oracle存储过程实例
  • oracle,mysql,SqlServer三种数据库的分页查询的实例
  • Oracle与Mysql主键、索引及分页的区别小结
  • oracle 分页问题解决方案
  • Oracle row_number() over()解析函数高效实现分页
  • oracle 分页 很棒的sql语句
  • php+oracle 分页类
  • 分页显示Oracle数据库记录的类之二
  • 分页显示Oracle数据库记录的类之一
  • Oracle实现分页查询的SQL语法汇总

// Free the resources that were used for this query
OCIFreeStatement($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
}

// Close the table
echo "</TABLE>";

} else {

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

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

// 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
}

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

// Parse the SQL string & execute it
$row_count=OCIParse($OracleDBConn, $sql_count);       
OCIExecute($row_count);

// If no page was specified in the url (ex. ),
// set it to page 1.
if (empty($page) || $page == 0) {
    $page = 1;
}

// 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.

    // Print a message stating that no records was found
    echo "<tr><td align=center>Sorry! No records was found</td></tr>";
}

if ($num_rows != 0) {

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

    // get number of columns for use later
    $num_columns = OCINumCols($rs);

// This query counts the records
$sql_count = "SELECT COUNT(*) FROM SAMPLE_TABLE";

?>
</BODY>
</HTML>

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

版权声明:本文由澳门新葡亰平台游戏发布于网络时代,转载请注明出处:一个ORACLE分页程序,javascript调节和测量检验原理