I'm building a small scale forum script in PHP, and I am having difficulty demonstrating the read/unread status of a given thread.
So, I have a particularly gargantuan query which returns the thread information, including the date it was first posted in, the date it was last posted in (if any) as well as the date it was last looked at by the currently logged in user (if such a date exists.
The query then returns three values:
- firstPostDate
- lastPostDate
- lastViewDate
What I need to check is that if firstPostDate or lastPostDate are more recent than lastViewDate then to mark that thread as being new / having unread replies.
I'm having problems executing this in PHP, due to the fact that my dates are all stored as timestamps in MySQL. At first I thought I could use UNIX_TIMESTAMP to return a Unix timestamp and then compare them, but I don't believe that I'm getting the correct results (because the timestamps are in Y-M-D H-M-S format (or similiar, I do not remember off the top of my head).
I have other queries in the site that compare two dates, and that appears to work well. Is there a way I can compare the two or three dates in a mysql query, and return a "YES" if it's new, or "NO" if it is not? It would make my PHP markup much simpler.
Or am I going about this the wrong way?