2013-05-03 49 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