I want to have a list for the next (Xbox) game release... And it works currently, but i want it to remove them from the list once that date has gone... so (example) record one has a release date of 10th november (11-10-2009) And it is the newest (next to be released in the whole table of records) So how can i make it so it goes from the list once that date has gone? -I don't need a coded solution as of yet, But im wondeirng can you give a mysql database a 'time' so once like (example) $release date < mysql time, then it goes from the list or something? -Is something along these lines possible? If not, are there any solutions? It would also be appricated if you share some of the code, if you do know an idea that could work. -Or how to give database a time or whatever your solution may be... Thanks alot, James
Sure, you'd want to create a table with a column named 'release_date' or something like that, and have it's data type set to 'DATE'. Using DATE and DATETIME are both valid options, but DATE will save space as it will only store the date in the format YYYY-MM-DD, while DATETIME will store the date AND the time as YYYY-MM-DD HH:MM:SS. Then, on your server, create a new cron job. Most hosting providers should provide some type of cron manager, which will make creating a cron a lot easier. If you're unsure of how they work, check out the documentation from your host, or just give the support department a call. Anyway, you'd set up a cron job that'd execute a PHP script every 24 hrs. This script will simply go through your database, find out which rows have a release_date less than today's date (a.k.a. yesterday), and remove em. Here's what it'd look like, assuming your table is named 'games' and the date column is 'release_date': cron_games.php <?php //Get today's date in the format YYYY-MM-DD $dToday = date( 'Y-m-d' ); //Delete rows where release_date is yesterday. mysql_query( "DELETE FROM games WHERE release_date < '$dToday'" ); ?> PHP: I did it this way instead of getting the actual date of yesterday just for smaller code.
yeah, you can do select query such that all the records prior to today or a specified date won't be shown. Please share table structure to help building exact query.
Wow, thank you very much conner, I know have it working And ha, better luck next time mastermunj, well I hope there not a next time...