jqgrid与postgresql分页

时间:2013-05-03 22:13:04

标签: mysql postgresql jqgrid

到目前为止,我正在使用jqgrid与mysql和php。我的代码适用于jqGrid演示站点中给出的示例 javascript部分提供的数据是:

  • page = 1
  • rows = 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变为限制0偏移8

1 个答案:

答案 0 :(得分:1)

在postgres中,

限制0,8 在mysql中意味着限制8偏移0

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