开发者

sort postgres table data in php through array

I have a postgres database with a table called workorders. In i开发者_如何学编程t 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.


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;


I suggest to order the rows through SQL (ORDER BY clause). It will be the most efficient way, specially if the date_out column is indexed.


While you really should do this via SQL, php's strtotime should translate it to a timestamp you can use for integer based comparison.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜