Phantom_guitarist wrote:
I am trying to write a query (in PHP) which selects from a database all of
the items which are in the future. My query is as follows
SELECT * FROM news WHERE ((news.date)>$today ORDER BY date
where news is my database, news.date is the the field which holds the date
for the item and $today will be replaced my current date.
At the moment it seems to display all values, which suggest its not
functioning properly.
Any suggestions are most welcome.
If the computer that runs the database server is in correct time, you
can also use:
SELECT * FROM news WHERE news.date > CURDATE() ORDER BY date;
The reason why your query is not working is impossible to tell from the
information you gave.
1. Check that dates are correct in your table.
2. Print/echo the query before using it to see what it looks like. I
think the $today is not valid. Most likely I bulieve that you are
missing '' around your data. i.e. you should have:
SELECT * FROM news WHERE news.date > '2004-04-02' ORDER BY date;
But again, it is even better to use curdate() function if the database
server is in correct time, like in previous example.