分页总是首先显示页面

时间:2015-11-10 08:16:41

标签: php oracle pagination

hy,我有一个问题,使用PHP和oracle数据库设置分页,页面只显示第一页的值。当我点击下一步按钮,页面从第1页更改为第2页,第3页等,但值仍然与第1页相同。我不知道,我也没有任何想法来修复此错误..

这是我设置记录集的代码..

<?php
// Set up recordset
define("ewSqlSelectCount", "SELECT count(*) count FROM sid_mst_dealer", true);
$sSql_count = BuildSqlang(ewSqlSelectCount, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sDbWhere, $sOrderBy);
//echo "$sSql_count" . "<br/ >";
$rs_count = moi_query($sSql_count , $conn) or die("Failed to execute query at line " . __LINE__ . ": " . moi_error($conn) . '<br>SQL: ' . $sSql);
//echo $rs_count;
oci_execute($rs_count);
$nTotalRecs = oci_fetch_array($rs_count);
$nTotalRecs = $nTotalRecs['COUNT'];

$rs = moi_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . moi_error($conn) . '<br>SQL: ' . $sSql);
//echo $rs;
oci_execute($rs);

if ($nDisplayRecs <= 0) { // Display all records
    $nDisplayRecs = $nTotalRecs;
}
$nStartRec = 1;
SetUpStartRec(); // Set up start record position
?>

这是函数..

function SetUpStartRec()
{

  // Check for a START parameter
  global $nStartRec;
  global $nDisplayRecs;
  global $nTotalRecs;
  if (strlen($_GET[ewTblStartRec]) > 0) 
  {
     $nStartRec = $_GET[ewTblStartRec];
     $_SESSION[ewSessionTblStartRec] = $nStartRec;
  } elseif (strlen($_GET["pageno"]) > 0) 
  {
     $nPageNo = $_GET["pageno"];
     if (is_numeric($nPageNo)) 
     {
         $nStartRec = ($nPageNo-1)*$nDisplayRecs+1;

         if ($nStartRec <= 0) 
         {
            // echo 'jangan ke sini';
            $nStartRec = 1;
         } 
         elseif ($nStartRec >= (($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1) 
         {
            $nStartRec = (($nTotalRecs-1)/$nDisplayRecs)*$nDisplayRecs+1;

         }
         $_SESSION[ewSessionTblStartRec] = $nStartRec;
     } 
     else 
     {

        $nStartRec = $_SESSION[ewSessionTblStartRec];
        if  (!(is_numeric($nStartRec)) || ($nStartRec == "")) 
        {
            $nStartRec = 1; // Reset start record counter
            $_SESSION[ewSessionTblStartRec] = $nStartRec;
        }
     }
 }

 else 
 {
     $nStartRec = @$_SESSION[ewSessionTblStartRec];
     if (!(is_numeric($nStartRec)) || ($nStartRec == "")) {
        $nStartRec = 1; // Reset start record counter

        $_SESSION[ewSessionTblStartRec] = $nStartRec;
     }
 }
}

这是查询

<?php
  define("ewTblVar", "sid_mst_dealer", true);
  define("ewTblRecPerPage", "RecPerPage", true);
  define("ewSessionTblRecPerPage", "sid_mst_dealer_RecPerPage", true);
  define("ewTblStartRec", "start", true);
  define("ewSessionTblStartRec", "sid_mst_dealer_start", true);
  define("ewTblShowMaster", "showmaster", true);
  define("ewSessionTblMasterKey", "sid_mst_dealer_MasterKey", true);
  define("ewSessionTblMasterWhere", "sid_mst_dealer_MasterWhere", true);
  define("ewSessionTblDetailWhere", "sid_mst_dealer_DetailWhere", true);
  define("ewSessionTblAdvSrch", "sid_mst_dealer_AdvSrch", true);
  define("ewTblBasicSrch", "psearch", true);
  define("ewSessionTblBasicSrch", "sid_mst_dealer_psearch", true);
  define("ewTblBasicSrchType", "psearchtype", true);
  define("ewSessionTblBasicSrchType", "sid_mst_dealer_psearchtype", true);
  define("ewSessionTblSearchWhere", "sid_mst_dealer_SearchWhere", true);
  define("ewSessionTblSort", "sid_mst_dealer_Sort", true);
  define("ewSessionTblOrderBy", "sid_mst_dealer_OrderBy", true);
  define("ewSessionTblKey", "sid_mst_dealer_Key", true);

  // Table level SQL
  define("ewSqlSelect", "SELECT * FROM sid_mst_dealer", true);
  if($_REQUEST[dealer_id]==""){
     if($_REQUEST[x_status]!=""){
     define("ewSqlWhere", " active_flag ='".$_REQUEST[x_status]."'", true);
    }else{
       define("ewSqlWhere", "active_flag='0'", true);
    }
  }else{
    define("ewSqlWhere", "", true);
   }
  define("ewSqlGroupBy", "", true);
  define("ewSqlHaving", "", true);
  define("ewSqlOrderBy", "", true);
  define("ewSqlOrderBySessions", "", true);
  define("ewSqlKeyWhere", "dealer_id = '@dealer_id'", true);
  define("ewSqlUserIDFilter", "", true);
?>

我真的需要帮助解决这个问题..谢谢你:D

3 个答案:

答案 0 :(得分:0)

我认为问题是在这个不起眼的SQL中缺乏限制,这是分页方面的关键部分。如果您考虑以下因素:

select * from `users` where `name`='fred' limit 0,10;

这将显示前10条记录,其中用户被称为“Fred”,然后是

select * from `users` where `name`='fred' limit 10,10;

第二个语句将显示用户名为“Fred”

的下10条记录

我根本不理解你构建sql的方法,但IMO你需要添加一个限制 - 和相关的逻辑来计算你所在的记录集中的page,以便你可以添加next / previous链接。

答案 1 :(得分:0)

这是分页..

{{1}}

答案 2 :(得分:0)

正如@RamRaider所说,你的分页方法有些模糊。 从Oracle 12c开始,您可以使用以下示例查询来实现分页。

SELECT fieldA,fieldB 
FROM table 
ORDER BY fieldA 
OFFSET 5 ROWS FETCH NEXT 14 ROWS ONLY;

访问this页面,了解有关Oracle Database 12c第1版(12.1)中前N个查询的行限制子句的更多信息