分页使用php和postgresql

时间:2013-02-14 10:48:46

标签: php javascript jquery sql postgresql

我在php文件中有一个postgresql查询,它返回了一百多条记录。我想在使用相同查询时每页只查看10条记录。我使用的查询如下:

SELECT
    to_char(a.CALLDATE,'yyyymm')            AS month,
    min(a.calldate)                         AS start_time,
    max(a.calldate)                         AS end_time,
    ceil(sum(a.CALLDURATION::integer) / 60) AS minutes,
    count(DISTINCT a.IDENTIFIANT)           AS distinct_callers,
    a.zoneiddest                            AS country_code,
    b.country
FROM cdr_data a,
     COUNTRY_CODES b
WHERE
    a.CALLSUBCLASS = '002'
AND
    a.CALLCLASS = '008'
AND
    a.zoneiddest::integer > 0
AND
    substr(a.CALLEDNUMBER, 1, 2) NOT IN ('77', '78', '75', '70', '71', '41', '31', '39', '76','79')
AND
    NOT substr(a.zoneiddest , 1 ,3) IN ('254','255','256','211','257','250','256')
AND
    trim(a.zoneiddest) = trim(b.country_code)
GROUP BY
    to_char(a.CALLDATE,'yyyymm'),
    a.zoneiddest,
    b.country
ORDER BY 1

我尝试过使用JavaScript,但它不起作用。有没有办法可以编辑这个查询或者在php中做些什么来实现我想要的东西?

如果有人在那里提供帮助,我将不胜感激,因为如果它与php和mysql的分页似乎有很多解决方案,但与php和postgresql没那么多。

1 个答案:

答案 0 :(得分:1)

简单的解决方案是追加:

OFFSET 20
LIMIT 10