首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用postgresql实现jqgrid分页

用postgresql实现jqgrid分页
EN

Stack Overflow用户
提问于 2013-05-03 22:13:04
回答 1查看 952关注 0票数 1

到目前为止,我还在mysql和php中使用jqgrid。我的代码适合于jqGrid演示站点中给出的示例。

javascript部分提供的数据如下:

  • 页=1
  • 行=8
  • sord=asc $page = $_ get ' page ';//获取请求的页面$limit =$_ get‘$limit’;//获取我们希望在网格中有多少行( $sidx =$_ get‘$sidx );//获取索引行--即用户单击$sord =$_ get’$sord‘;//获取方向如果(!$sidx)$sidx =1;//连接到数据库$connection = mysql_connect($serveur,$user,$password);$db = mysql_select_db($bdd,$connection);Mysql_query(“设置名称'utf8'");$query =”选择计数(*)作为从首选项中的计数(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/$限度);$start = $limit*$page - $limit;//不要将$limit*($page - 1) if ($start<0) $start = 0;$query = "select * from Preferences (Id_Membre ='$idm') order by $sidx $sord LIMIT $start,$limit";$result = mysql_query($query,$connection);

最后一个查询返回4行。

这是与Postgresql相同的代码。对于相同的数据,这段代码什么也不返回!

代码语言:javascript
复制
    $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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-04 01:16:36

mysql中的限制为0,8,这意味着postgres中的限制8偏移量为0

代码语言:javascript
复制
$query = "select * from preference where (id_membre ='$idm') 
    order by $sidx $sord LIMIT $limit OFFSET $start";
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16368336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档