【发布时间】:2021-01-27 18:47:13
【问题描述】:
我的问题有点令人困惑,
我的数据库中有事件 每个事件都有自己的开始日期和结束日期 所以我创建了三个表
-
第一个用于公开活动
-
第二个是未打开的事件
-
最后一个是关闭的事件
所以我想创建用于创建表行的 foreach 循环,并按开始日期对第二个进行排序,并按结束日期对第一个和最后一个进行排序
谢谢
我的尝试:
<table>
<thead>
<tr>
.
.
.
</tr>
</thead>
<tbody>
<?php
sort($rows);
$u = 0;
foreach ($rows as $row) :
$u++;
$university = getUniversityByBsc($row['id']);
if ($today < $row['date_end'] && $today > $row['date']) :
?>
<tr>
.
.
.
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
.
.
.
</tr>
</tfoot>
</table>
<table>
<thead>
<tr>
.
.
.
</tr>
</thead>
<tbody>
<?php
sort($rows);
$u = 0;
foreach ($rows as $row) :
$u++;
$university = getUniversityByBsc($row['id']);
if ($today > $row['date_end'] && $today > $row['date']) :
?>
<tr>
.
.
.
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
.
.
.
</tr>
</tfoot>
</table>
<table>
<thead>
<tr>
.
.
.
</tr>
</thead>
<tbody>
<?php
sort($rows);
$u = 0;
foreach ($rows as $row) :
$u++;
$university = getUniversityByBsc($row['id']);
if ($today < $row['date_end'] && $today < $row['date']) :
?>
<tr>
.
.
.
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
.
.
.
</tr>
</tfoot>
</table>
【问题讨论】:
-
欢迎您,到目前为止您尝试了什么
-
您的结构一开始似乎不是最佳的。你有三个单独的表真的有充分的理由吗?对于这三种状态,你有很多不同的数据吗?
-
不,我没有结构,但这种类型的事件需要一些分离
-
表是指 3 个 HTML 表而不是 DB 表?您不能对您的案例使用排序。看看usort()
-
是的,当然我的意思是 3 个 html 表格