0

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.

1 Answer 1

2

Simple solution would be to append:

OFFSET 20
LIMIT 10
Sign up to request clarification or add additional context in comments.

4 Comments

you mean like this: order by 1, OFFSET 20 ,LIMIT 10
@roykasa: Yes, just without ,.
But what would be a long solution in case i want to view past records without diving back into the code and changing the offset and limit values?
@roykasa: I don't quite follow. For different results you have to change the query somehow. You could use a cursor for consistent results within a session/transaction (depends). But that's rarely useful for web use where you'd normally use connection pools or don't want to keep connections open and exclusive for one client indefinitely ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.