deleting a mysql table row based on current date and table date
I am trying to make a webpage that deals with seminars postings. I would
like the page to delete a seminar that is past its expiration date (or the
date that the seminar occurs) My table has 3 date slots, one for month,
one for day, one for year. They are all integers in the table.
if(date("Y") > $info['year']) //if the year is old
{ $sql = "DELETE FROM seminars WHERE ID = '$ID'";
mysql_query($sql); } //then delete this seminar
else if(date("Y") == $info['year'] && date("n") > $info['month']) //if we
are in the year of the seminar, but the month is now old
{ $sql = "DELETE FROM seminars WHERE ID = '$ID'";
mysql_query($sql);} // then delete this seminar
else if(date("Y") == $info['year'] && date("n") == $info['month'] &&
date("j") > $info['day']) //if we are in the year of the seminar and the
month of the seminar, but the day is old
{ $sql = "DELETE FROM seminars WHERE ID = '$ID'";
mysql_query($sql); } // then delete this seminar
else // if there is no reason to delete the seminar then print out this
seminar
as can be seen above I tried to use the system time for year month day and
compared each one to see if anything was old. However, it is never
deleting the seminars.
now, $info is the table row, because this statement is in a while loop so
that it can grab every row from the table. but even if the delete
statement wasnt working, then it wouldnt display the seminar right? the
last else statement is where displaying the seminar begins by the way.
if anyone knows a better way to do this I would appreciate it a lot. I
have been struggling with this for a while now.
Thanks!
No comments:
Post a Comment