我正在使用别人的代码,并试图做一个简单的添加。我在 mySQL 数据库中有一些数据,其中一列是 time_end,它是未来设置的日期。一旦该日期过去,我想显示特定文本。
$events = get_all_events();
include 'templates/bet.php';
function get_all_events() {
global $_DB;
$stm = $_DB->prepare('select wl_bet.*, wl_group.gname, (select count(*) from wl_betplace where wl_betplace.betid = wl_bet.id) as countBet from wl_bet, wl_group where wl_bet.groupid = wl_group.gid order by time_end asc');
$stm->execute();
$data = $stm->fetchAll();
$close = array();
$active = array();
$paid = array();
$p = 0;
$c = 0;
$a = 0;
foreach ($data as $d) {
if ($d['status'] == 2) {
if ($p < 5) {
array_push($paid, $d);
$p++;
}
}
else {
if ($d['time_end'] < time()) {
if ($c < 5) {
array_push($close, $d);
$c++;
}
}
else {
if ($a < 8) {
array_push($active, $d);
$a++;
}
}
}
}
return array('close' => $close, 'active' => $active, 'paid' => $paid);
}
如果当前日期超过 time_end 日期,这是我要显示的表格。我知道这应该像 if 语句一样简单,但我似乎无法做到正确。同样,我要做的就是在当前日期大于 mysql 数据库中的日期 (time_end) 时显示此表。
<table width="100%" class="list-details sortable">
<tr class="tablebar">
<th><div>Title</div></th>
<th><div>Event Date</div></th>
<th><div># of Bets</div></th>
</tr>
<?php foreach ($events['close'] as $c) : ?>
<tr class="row">
<td><a href="?cmd=view-bet&id=<?php echo $c['id']; ?>"><?php echo $c['title']; ?></a></td>
<td><?php echo format_date_only($c['time_end']); ?></td>
<td><?php echo $c['countBet']; ?></td>
</tr>
<?php endforeach; ?>
</table>