roykasa
roykasa

Reputation: 3027

Pagination using php and postgresql

I have a postgresql query in the php file that returns over a hundred records. I would like to view only 10 records per page while using the same query. The query I am using is as below:

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

I have tried using JavaScript but it wont work. Is there a way I can edit this query or the do something in php to be able to achieve what I want?

I would be grateful if someone out there help because there seem to be numerous solutions if its pagination with php and mysql but not so much with php and postgresql.

Upvotes: 0

Views: 1055

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 656744

Simple solution would be to append:

OFFSET 20
LIMIT 10

Upvotes: 2

Related Questions