希望每个人都很棒。在PHP和SQL生成的事件列表中仅显示未来事件的最佳方法是什么。
function select_events($sql) {
include 'connect.php';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table id='event-list'>\n
<tr>\n
<th id='event'>Event</th>\n
<th id='date-of-event'>Date</th>\n
<th id='time'>Time</th>\n
<th id='place'>Place</th>\n
<th id='admission'>Admission</th>\n
</tr>";
}
while ($row = $result->fetch_assoc()) {
$date = new DateTime($row['date']);
$formatted_date = $date->format('d/m/Y');
$time = new DateTime($row['time']);
$formatted_time = $time->format('HH:MM');
echo "<tr>\n
<td id='event'>".$row['event']."</td>\n
<td id='date-of-event'>".$formatted_date."</td>\n
<td id='time'>".$row['time']."</td>\n
<td id='place'>".$row['place']."</td>\n
<td id='admission'>".$row['admissions']."</td>\n
</tr>\n";
}
echo "</table>\n";
}
<?php select_events("SElECT * FROM events ORDER BY date, time"); ?>
提前感谢大家。 :)
答案 0 :(得分:0)
试试这个,
<?php select_events("SElECT * FROM events WHERE `date` >= CURDATE() ORDER BY `date`, `time`"); ?>
为mysql保留关键字使用反引号
答案 1 :(得分:0)
您需要添加一个条件来检查日期和时间。
检查日期是否大于今天且时间大于当前时间。
<?php select_events("SElECT * FROM events WHERE `date` >= " . date('Y-m-d') . " AND `time` > " . date('H:i:s') . " ORDER BY `date`, time"); ?>