Php – sort postgres table data in php through array

PHPpostgresqlsql

I have a postgres database with a table called workorders. In it is a column called date_out where the date is recorded like 2009-09-23. I want to sort this table data in a php page based on a users date range, ie, sort the table by date begin 2009-09-01 end 2009-09-31. Its for an accounts package I am creating for my company. Is there anyway I can do this. I can connect to my database but don't know how to sort the data. Also can I limit the number of views to say 15 lines, then onto a next page? Thanks for anyone that can help me out.

Best Answer

I'm not sure why you'd need PHP since this is a job which postgres can easily handle:

SELECT
    visitdate
FROM
    public.statistics
WHERE
    visitdate 
        between date '2009-10-19' and date '2009-10-20'
ORDER BY
    visitdate
OFFSET 2
LIMIT 3;