【问题标题】:jqgrid pagination with postgresql使用 postgresql 进行 jqgrid 分页
【发布时间】:2013-05-03 22:13:04
【问题描述】:

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

  • 页面=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);    

有什么想法吗? 我以为limit 0,8变成了limit 0 offset 8

【问题讨论】:

    标签: mysql postgresql jqgrid


    【解决方案1】:

    limit 0,8 in mysql 表示 limit 8 offset 0 in postgres。

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

    【讨论】:

    • limit $a,$b 表示限制 $b 偏移 $a。一些stackoverflow用户给出了相反的意见!
    猜你喜欢
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 2018-01-03
    • 2012-10-20
    • 2019-01-15
    • 2016-06-12
    相关资源
    最近更新 更多