I’m trying to list out news using php and mysql based on the publish date and the time-stamp of the news article. I need all articles to list with the newest publish date and most recent time-stamp. I’m getting some irregularities in the listings when i attempt to accomplish this.
To note, some news articles could have a timestamp of today but a publish date of 10 from now.
SELECT * FROM table_news WHERE pubdate <= ".time()." ORDER BY pubdate,date DESC
SELECT * FROM table_news WHERE pubdate <= ".time()." ORDER BY date,pubdate DESC
SELECT * FROM table_news WHERE pubdate <= ".time()." ORDER BY pubdate,date ASC
SELECT * FROM table_news WHERE pubdate <= ".time()." ORDER BY date,pubdate ASC
None of these work…
I can list some of the results but i thought it might be a bit redundant. Let me know if you’d like to see them.
I’m either missing something obvious (long hours this week…) or there is a more creative approach to this.
Thanks for the help!
Is your
pubdatefield a unix timestmap (e.g. an integer field), or an actual mysql date/time field?time()returns a unix timestamp, not a date/time string. Use this instead:Note the
DESCon both fields in the order by clause. unless you specify asc/desc explicitly on each field in an order-by clause, SQL specifies defaulting to ASC.