很简单呀,无论什么数据库,用 limit 字句就可以啦
$records_everypage=20;
$start=$thispage*$records_everypage;
$sql="select * from mytable limit $start,$records_everypage";
...

解决方案 »

  1.   

    把下面的mysql语句换成相应的oracle语句即可的啊:用PHP实现MySQL数据分页显示一例. 
    <?
    /*
    作者: 何志强[[email protected] [email protected]]
    主页: http://www.phpchina.com/
    ICQ : 50721529
    版本: 1.0未经本人同意,不得以任何方式转载*/$pagesize = 2; //每页显示的记录数$pageno = (int)$pageno;
    if($pageno<1) $pageno = 1;$start_rowno = ($pageno-1)*$pagesize;$con = mysql_connect('localhost','test','') or die('无法连接服务器');$sql = 'select * from page_test LIMIT '.$start_rowno.','.($pagesize+1); //$pagesize加1的目的是用来判断是否有下一页
    $rst = mysql_db_query('test',$sql,$con) or die($sql.'语句出错');$num_rows = mysql_num_rows($rst);
    if($num_rows>$pagesize){
       $num_rows = $pagesize;
       echo '<a href="'.$PHP_SELF.'?pageno='.($pageno+1).'">下一页</a>&nbsp;&nbsp;';
    }
    if($pageno>1) echo '<a href="'.$PHP_SELF.'?pageno='.($pageno-1).'">上一页</a>&nbsp;&nbsp;';echo '<table border="1" cellspacing="0" cellpadding="0">';
    echo '<tr>';
    $num_fields = mysql_num_fields($rst);
    for($i=0;$i<$num_fields;$i++) echo '<th>'.mysql_field_name($rst,$i).'</th>';
    for($i=0;$i<$num_rows;$i++){
       $row=mysql_fetch_row($rst);
       echo '<tr>';
       for($j=0;$j<$num_fields;$j++) echo '<td>&nbsp;'.$row[$j].'</td>';
       echo '</tr>';
    }
    echo '</tr>';
    echo '</table>';mysql_free_result($rst);mysql_close($con);
    ?>
      

  2.   

    我说了要给我加分呀
    首先oracle+php关键在oracle的用法上.oracle没有limit语法所以不能用这句
    oracle实现方法为
    select field1,field2,n  form (select field1,field2,ROWNUM n from table) where n>$min and n<$max
    你也可以试试
    select field1,field2,rownum n  form  table where n>$min and n<$max
    其中field1,field2表示你要查的字段,table是你要查的表,n是记录的序号
      

  3.   

    哈哈,看来真正的高手终于出现了,我们都以mysql来代替oracle了,真是抱歉啊
      

  4.   

    mysql可以用limit
    oracle的rownum也不是表示的数据库中的数据具体存储位置,怎么可以?
      

  5.   

    to yangknight 你对oracle还不熟,你试试就知道了。
      

  6.   

    to yangknight(侠客在线) ORACLE 的ROWID 到底是以什么形式记录?
    想知道。。
      

  7.   

    在oracle里面实现翻页可以使用oracle的游标,limit语法是不能适用于oracle的
      

  8.   

    不能,因为游标是在查询出来的结果集快照里进行操作的,所以如果愿记录修改,游标是不能更新的。不过在web页面的应用上不需要考虑这个问题,因为每刷新一次都会查询最新的结果进行快照。
      

  9.   

    比如我要翻页,怎么保证上一次查询的纪录条数和我这次查询条数相同?是用ID吗?要是ID不连续怎么办?
    to yorgo 你不要只说,像我一样写出实现代码
      

  10.   

    For each row in the database, the ROWID pseudocolumn returns a row's address. Oracle8i rowid values contain information necessary to locate a row: the data object number of the object which data block in the datafile which row in the data block (first row is 0) which datafile (first file is 1). The file number is relative to the tablespace. Usually, a rowid value uniquely identifies a row in the database. However, rows in different tables that are stored together in the same cluster can have the same rowid. Values of the ROWID pseudocolumn have the datatype ROWID or UROWID. For more information, see "ROWID Datatype" and "UROWID Datatype". Rowid values have several important uses: They are the fastest way to access a single row. They can show you how a table's rows are stored. They are unique identifiers for rows in a table. You should not use ROWID as a table's primary key. If you delete and reinsert a row with the Import and Export utilities, for example, its rowid may change. If you delete a row, Oracle may reassign its rowid to a new row inserted later. Although you can use the ROWID pseudocolumn in the SELECT and WHERE clause of a query, these pseudocolumn values are not actually stored in the database. You cannot insert, update, or delete a value of the ROWID pseudocolumn. 
    ---------------------------------------------------------------------------------
    ROWNUM 
    For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on. You can use ROWNUM to limit the number of rows returned by a query, as in this example: SELECT * FROM emp WHERE ROWNUM < 10;
    If an ORDER BY clause follows ROWNUM in the same subquery, the rows will be reordered by the ORDER BY clause. The results can vary depending on the way the rows are accessed. For example, if the ORDER BY clause causes Oracle to use an index to access the data, Oracle may retrieve the rows in a different order than without the index. Therefore, the following statement will not have the same effect as the preceding example: SELECT * FROM emp WHERE ROWNUM < 11 ORDER BY empno;If you embed the ORDER BY clause in a subquery and place the ROWNUM condition in the top-level query, you can force the ROWNUM condition to be applied after the ordering of the rows. For example, the following query returns the 10 smallest employee numbers. This is sometimes referred to as a "top-N query": SELECT * FROM
       (SELECT empno FROM emp ORDER BY empno)
       WHERE ROWNUM < 11;
    In the preceding example, the ROWNUM values are those of the top-level SELECT statement, so they are generated after the rows have already been ordered by EMPNO in the subquery. For more information about top-N queries, see Oracle8i Application Developer's Guide - Fundamentals. Conditions testing for ROWNUM values greater than a positive integer are always false. For example, this query returns no rows: SELECT * FROM emp
        WHERE ROWNUM > 1;
    The first row fetched is assigned a ROWNUM of 1 and makes the condition false. The second row to be fetched is now the first row and is also assigned a ROWNUM of 1 and makes the condition false. All rows subsequently fail to satisfy the condition, so no rows are returned. You can also use ROWNUM to assign unique values to each row of a table, as in this example: UPDATE tabx
        SET col1 = ROWNUM;
      

  11.   

    Example
    This statement selects the address of all rows that contain data for employees in department 20: SELECT ROWID, ename  
       FROM emp
       WHERE deptno = 20;
     
    ROWID              ENAME
    ------------------ ----------
    AAAAqYAABAAAEPvAAA SMITH
    AAAAqYAABAAAEPvAAD JONES
    AAAAqYAABAAAEPvAAH SCOTT
    AAAAqYAABAAAEPvAAK ADAMS
    AAAAqYAABAAAEPvAAM FORD
      

  12.   

    <?php /********************************************* 
    TOracleViewPage v 1.0 分页显示Oracle数据库记录的类 作者:sharetop 
    email:[email protected] ***********************************************/ 
    class TOracleViewPage { var $Table; //表名 
    var $MaxLine; //每页显示行数 var $LinkId; 
    var $Id; var $Offset; //记录偏移量 
    var $Total; //记录总数 
    var $Number; //本页读取的记录数 
    var $Result; //读出的结果 var $TPages; //总页数 
    var $CPages; //当前页数 var $TGroup; 
    var $PGroup; //每页显示的页号个数 
    var $CGroup; var $Condition; //显示条件 如:where id='$id' order by id desc 
    var $PageQuery; //分页显示要传递的参数 
    //******构造函数************* 
    //参数:表名、最大行数、分页参考的字段、每页显示的页号数 function TOracleViewPage($TB,$ML,$ID){ 
    global $offset; $this->Table=$TB; 
    $this->MaxLine=$ML; 
    $this->Id=$ID; if(isset($offset)) $this->Offset=$offset; 
    else $this->Offset=0; $this->Condition=""; 
    $this->PageQury=NULL; 
    } function InitDB($user,$password,$db){ 
    if (PHP_OS == "WINNT") $dllid=dl("php3_oci80.dll"); 
    $this->LinkId = OCILogon($user,$password,$db); 
    } function Destroy(){ 
    OCILogoff($this->LinkId); 
    } //********设置显示条件********* 
    //如:where id='$id' order by id desc 
    //要求是字串,符合SQL语法(本字串将加在SQL语句后) function SetCondition($s){ 
    $this->Condition=$s; 
    } function SetNumGroup($pg){ 
    $this->PGroup=$pg; 
    } //******设置传递参数************ 
    // key参数名 value参数值 
    // 如:setpagequery("id",$id);如有多个参数要传递,可多次调用本函数。 function SetPageQuery($key,$value){ 
    $tmp[key]=$key; $tmp[value]=$value; 
    $this->PageQuery[]=$tmp; 
    } //********读取记录*************** 
    // 主要工作函数,根据所给的条件从表中读取相应的记录 
    // 返回值是一个二维数组,Result[记录号][字段名] function ReadList() { 
    $SQL="SELECT Count(*) AS total FROM ".$this->Table." ".$this->Condition; $stmt = OCIParse($this->LinkId,$SQL); 
    $bool = OCIExecute($stmt); 
    if (!$bool) { 
    echo "连接失败!"; 
    OCILogoff($this->LinkId); 
    exit; 

    else { 
    OCIFetch($stmt); 
    $this->Total=OCIResult($stmt,1); 

    /*****此句要求ID为连续的。 
    $SQL="SELECT * FROM ".$this->Table." ".$this->Condition. 
    " WHERE ".$this->Id." BETWEEN ".$this->Offset." AND ".($this->Offset+$this->MaxLine-1); 
    ******/ $SQL="SELECT * FROM ".$this->Table." ".$this->Condition." ORDER BY ".$this->Id; $stmt = OCIParse($this->LinkId,$SQL); 
    $bool = OCIExecute($stmt); 
    if (!$bool) { 
    echo "连接失败!"; 
    OCILogoff($this->LinkId); 
    exit; 

    else { 
    $ncols = OCINumCols($stmt); 
    for ( $i = 1; $i <= $ncols; $i++ ) 
    $column_name[$i] = OCIColumnName($stmt,$i); 
    $k=0; //while(OCIFetch($stmt)) { 此句与上句一样,要求ID为连续。 for($j=0;$j<$this->Offset;$j++) OCIFetch($stmt); 
    for($j=0;$j<$this->MaxLine;$j++){ 
    if(OCIFetch($stmt)){ 
    $k++; 
    for($i=1;$i<=$ncols;$i++) 
    $temp[$column_name[$i]]=OCIResult($stmt,$i); 
    $this->Result[]=$temp; 

    else break; 

    $this->Number=$k; 
    OCILogoff($this->LinkId); } 
    return $this->Result; 
    } //************取总页数及当前页************* function GetPage(){ 
    $this->TPages=ceil($this->Total/$this->MaxLine); 
    $this->CPages=ceil($this->Offset/$this->MaxLine)+1; 
    } //**********显示页数************* 
    //显示当前页及总页数 function ThePage() { 
    echo "第".$this->CPages."页/共".$this->TPages."页"; 
    } //**********显示翻页按钮************* 
    //此函数要在getPage()函数之后调用!!! 
    //显示首页、下页、上页、未页,并加上要传递的参数 function Page() { 
    $first=0; 
    $next=$this->Offset+$this->MaxLine; 
    $prev=$this->Offset-$this->MaxLine; 
    $last=($this->TPages-1)*$this->MaxLine; $k=count($this->PageQuery); 
    $strQuery=""; //生成一个要传递参数字串 
    for($i=0;$i<$k;$i++){ 
    $strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value]; 
    } if($this->Offset>=$this->MaxLine) 
    echo "<A href=$PHP_SELF?offset=".$first.$strQuery.">首页</A>|"; 
    else echo "首页|"; if($prev>=0) 
    echo "<A href=$PHP_SELF?offset=".$prev.$strQuery.">上一页</A>|"; 
    else 
    echo "上一页|"; if($next<$this->Total) 
    echo "<A href=$PHP_SELF?offset=".$next.$strQuery.">下一页</A>|"; 
    else 
    echo "下一页|"; if($this->TPages!=0 && $this->CPages<$this->TPages) 
    echo "<A href=$PHP_SELF?offset=".$last.$strQuery.">末页</A>"; 
    else 
    echo "末页"; 
    } //*******取分组信息******* function GetGroup() { 
    $this->TGroup=ceil($this->TPages/$this->PGroup); 
    $this->CGroup=ceil($this->CPages/$this->PGroup); 
    } //******分组显示页号****** 
    //显示如:1 2 3 4 function NumPage() { 
    $first=($this->CGroup-1)*($this->PGroup)+1; 
    $last=($first+$this->PGroup > $this->TPages)? ($this->TPages+1):($first+$this->PGroup); 
    $pr=($this->CGroup-2>=0)?( ($this->CGroup-2)*($this->PGroup)+1 ):(-1); 
    $prev=($pr!=-1)?( ($pr-1)*$this->MaxLine):(0); 
    $ne=($this->CGroup*$this->PGroup+1<=$this->TPages)?($this->CGroup*$this->PGroup+1):(-1); 
    $next=($ne!=-1)?( ($ne-1)*$this->MaxLine):(0); $k=count($this->PageQuery); 
    $strQuery=""; //生成一个要传递参数字串 
    for($i=0;$i<$k;$i++){ 
    $strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value]; 
    } if($first!=1) 
    echo "<a href=$PHP_SELF?offset=".$prev.$strQuery."> << </a>"; 
    for($i=$first;$i<$last;$i++) { 
    if($this->CPages!=$i){ 
    $current=($i-1)*$this->MaxLine; 
    echo "<a href=$PHP_SELF?offset=".$current.$strQuery.">".$i."</a> "; 

    else echo $i." "; 

    if($ne!=-1) 
    echo "<a href=$PHP_SELF?offset=".$next.$strQuery."> >> </a>"; 
    } //******end class 

    ?> 
      

  13.   

    to sunqj ????我真佩服老兄的
    我上面写的你没试过吗?
    select 字段一,字段二,....,n  form (select 字段一,字段二,....,ROWNUM n from table) where n>$min and n<$max
    不就解决了?要那么复杂吗?