Could someone recommend a good resource, either online or a book, that
explains how to display data on a web page according to the current
date using PHP/MySQL?
Today is June 21, 2004. I want my web page to display Item 1 but not
Items 2 and 3. On June 23, my page displays Items 2 and 3 but Item 1
has "expired" and is no longer displayed.
I've really spent some time searching for than answer online,
including the PHP and MySQL manuals, but I can't find precisely what
I'm looking for. Be gentle if I'm an idiot and have overlooked
something obvious.
I like to keep things as straightforward as possible. Assuming your
columns are named as above and are DATE columns, not DATETIME, the
following statement will select only those rows within your range. Note
that the comparison checks *both* starting date and ending date.
SELECT * FROM tablename WHERE CURDATE() BETWEEN StartDate AND EndDate
From the MySQL pages:
CURDATE() Returns the current date as a value in 'YYYY-MM-DD' or
YYYYMMDD format, depending on whether the function is used in a string
or numeric context.
mysql> SELECT CURDATE();
-> '1997-12-15'
mysql> SELECT CURDATE() + 0;
-> 19971215
Note that CURRENT_DATE and CURRENT_DATE() are synonymous with CURDATE().
Hope This Helps,
Tim
--
Timothy Binder, President
Philadelphia Science Fiction Society <http://www.psfs.org/>
Upcoming Programming: Hugo Panel, Mark Wolverton
_______________________________________________
web-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/web-development
Do not post admin requests to the list. They will be ignored.