到目前为止,我一直在使用 jqgrid 和 mysql 以及 php。我的代码适用于 jqGrid 演示站点中给出的示例。
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
最佳答案
limit 0,8 在 mysql 中意味着 limit 8 offset 0 在 postgres 中。
$query = "select * from preference where (id_membre ='$idm')
order by $sidx $sord LIMIT $limit OFFSET $start";
关于mysql - jqgrid 分页与 postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16368336/