2013-05-03 45 views
0

直到現在我使用jqgrid與MySQL和PHP。我的代碼適用於jqGrid演示網站中給出的示例。
由JavaScript部分所提供的數據是:jqgrid與postgresql分頁

  • 頁= 1個
  • 行= 8
  • SORD = ASC

    $page = $_GET['page']; // get the requested page 
    $limit = $_GET['rows']; // get how many rows we want to have into the grid 
    $sidx = $_GET['sidx']; // get index row - i.e. user click to sort 
    $sord = $_GET['sord']; // get the direction 
    if(!$sidx) $sidx =1; // connect to the database  
    $connection = mysql_connect($serveur,$user,$password); 
    $db = mysql_select_db($bdd, $connection); 
    mysql_query("set names 'utf8'"); 
    $query = "SELECT COUNT(*) AS count FROM Preferences WHERE (Id_Membre ='$idm')"; 
    $result = mysql_query($query,$connection); 
    $row = mysql_fetch_array($result); 
    $count = $row['count']; 
    if($count > 0 && $limit > 0) { 
        $total_pages = ceil($count/$limit); 
    } 
    else { 
        $total_pages = 0; 
    } 
    
    if ($page > $total_pages) $page=$total_pages; 
    
    $start = $limit*$page - $limit; // do not put $limit*($page - 1) 
    if ($start<0) $start = 0; 
    $query = "select * from Preferences where (Id_Membre ='$idm') order by $sidx $sord LIMIT $start , $limit"; 
    $result = mysql_query($query, $connection); 
    

的最後查詢將返回4行。

這是適用於Postgresql的相同代碼。使用相同的數據,此代碼不會返回任何內容!

$page = $_GET['page']; // get the requested page 
    $limit = $_GET['rows']; // get how many rows we want to have into the grid 
    $sidx = $_GET['sidx']; // get index row - i.e. user click to sort 
    $sord = $_GET['sord']; // get the direction 
    if (!$sidx) $sidx =1; // connect to the database  
    $connection = pg_connect($con); 

    pg_query($connection,"set names 'utf8'"); 
    $query = "SELECT COUNT(*) AS count FROM preference WHERE (id_membre ='$idm')"; 
    $result = pg_query($connection,$query); 
    $row = pg_fetch_array($result); 
    $count = $row['count']; 
    if($count > 0 && $limit > 0) { 
     $total_pages = ceil($count/$limit); 
    } 
    else { 
     $total_pages = 0; 
    } 

    if ($page > $total_pages) $page=$total_pages; 

    $start = $limit*$page - $limit; // do not put $limit*($page - 1) 
    if ($start<0) $start = 0; 
    $query = "select * from preference where (id_membre ='$idm') order by $sidx $sord LIMIT $start OFFSET $limit"; 
    $result = pg_query($connection,$query);  

任何想法? 我認爲限制0,8 becomed極限0偏移8

回答

1

極限0,8在MySQL裝置極限8 postgres的偏移0

$query = "select * from preference where (id_membre ='$idm') 
    order by $sidx $sord LIMIT $limit OFFSET $start"; 
+0

限制$ a,$ b表示限制$ b偏移$ a。一些stackoverflow用戶相反! – Bertaud 2013-05-04 13:59:36