我正在尝试制作一个网页,讨论研讨会发布内容。我希望该页面删除已过期(或研讨会发生日期)的研讨会 我的表格有3个日期插槽,一个为月份,一个为日期,一个为年份。他们都是桌子上的整数。根据当前日期和表格日期删除mysql表格行
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
从上面可以看出,我试图使用系统时间为年份一天,并比较每个人看看是否有什么旧的。但是,它从不删除研讨会。
现在,$info
是表行,因为此语句位于while循环中,因此它可以抓取表中的每一行。但即使删除语句不起作用,那么它也不会显示研讨会的权利?最后的陈述是展示研讨会的地方。
如果有人知道更好的方法来做到这一点,我将不胜感激。我一直在为此苦苦挣扎了一段时间。
“我希望页面删除超过其到期日期(或研讨会发生日期)的研讨会“是否有具体理由说明为什么不使用MySQL DATETIME列类型? – u54r
我不知道如何将我从表单中获取的日期转换为该数据类型。 – ForgottenOne
'$ year。 ' - '。 $月。 ' - '。 $ date'给你一个有效的MySQL'DATE'。 – TheWolf