如果当前日期在页面日期之后 - 删除页面?
问题描述:
我想知道是否有方法让您使用PHP根据日期删除内容?我有一个页面列出日期范围内的事件,我希望它删除已通过的事件。如果当前日期在页面日期之后 - 删除页面?
I.e.
If start date is before current date = remove event
If start date is after current date = keep event
If start date is equal to current date = highlight event.
答
你从哪里得到这些事件? 它是从数据库中提取的。 并且是开始日期存储在数据库中。
如果数据库中存在这种情况,那么您必须根据您在数据库中保存的格式在php中编写代码。
您可以使用PHP date()函数来做到这一点
答
你可以简单地添加一些SQL一个删除(或存档),其中日期已过事件。我假设这些信息在数据库中。
或者你可以简单地使用if语句,所以如果开始日期<当前日期不显示。
如果您使用的是数据库,只需选择未来的事件即可。
答
也许像一些逻辑:
//psudeocode
//you could also use a foreach() if you are working with an array()
//start date greater then or equal to current date
if ($start_date >= $cur_date){
//do some stuf with the events
if ($start_date == $cur_date) {
//add hilighting
}
//else sart date is less then current date unset/delete/toss out
} else {
unset $event['old event'];
}
您使用的数据库?如果你不是,你应该。 – jeroen 2012-02-09 13:40:26