0

我有几个问题。我希望能够获取放在一起的所有事件的最小值 [最早] (start_time)和最大值 [最新] (end_time),但是,我只想选择日期发生的事件的最大值和最小值下面.... ($date0_post)... [请注意,我将复制这七次,以复制一周的风格...所以“+0 日”最终将具有一个功能,即:“+1 天”、“+2 天”等]

$date0 = strtotime("+0 day");
$date0_post = date('Y-m-d', $date0);

下面是我认为它可能如何工作的一个例子,但是,我确信我做错了:

$sql = "SELECT max(end_time), min(start_time) FROM events WHERE date='$date0_post' AND course='$courseid'";
$query = mysqli_query($db_conx, $sql);
while($row = mysqli_fetch_assoc($query)){
$event_min_start = $row["start_time"];    
$event_max_end = $row["end_time"];
}

另外,我有变量$coursetee_open_time_mysql$coursetee_close_time_mysql ...日期时间格式(这些最大值和最小值的格式相同)...下面是一个 if 语句,声明如果:
任何事件的 MIN-START 时间那一天比课程的开放时间早,当天任何活动的最大结束时间都比关闭时间早,然后echo '<option value="1" disabled>Closed for '.$closed_reason.'</option>';

if ($event_min_start < $coursetee_open_time_mysql && $coursetee_close_time_mysql < $event_max_end) {
echo '<option value="1" disabled>Closed for '.$closed_reason.'</option>';
} else {
echo '<option value="1">Today</option>';
}
4

1 回答 1

0

I was over thinking it, I fixed it and turned three fetches into one...thankyou @hd1 for leading me in the correct dirrection.

$sql = "select reason, min(start_time) AS start_time, max(end_time) AS end_time FROM events WHERE date='$date_post' AND course='$courseid'";
$query = mysqli_query($db_conx, $sql);
while($row = mysqli_fetch_assoc($query)){
$event_max_end = $row["end_time"];
$event_min_start = $row["start_time"];
$event_reason = $row["reason"];
}
于 2013-07-15T03:13:33.870 回答