如何在 php 排序之间插入水平线



我不知道从哪里开始。 我有代码选择数据并根据两列对其进行排序。

<?php // Query member data from the database and ready it for display
$sql1 = mysql_query("SELECT id, Name, Age, Rank, Ring, Time FROM competitors ORDER BY Time  ASC, Ring + 0 ASC");
while($row1 = mysql_fetch_array($sql1)){
$name =$row1["Name"];
$age =$row1["Age"];
$rank=$row1["Rank"];
$ring1=$row1["Ring"];
$time1=$row1["Time"];
?>

然后,它显示数据并基于两列进行排序

<?php echo $time1; echo $ring1; ?>

它将显示这样的东西(是的,我知道我发布的代码实际上并没有显示这个,但它只是一个概念(

振铃时间

1 10:00

1 10:00

1 10:00

1 11:00

1 11:00

1 11:00

我想知道如何让它在第一次排序完成后插入水平规则。 所以它看起来更像这样:

1 10:00

1 10:00

1 10:00


1 11:00

1 11:00

1 11:00

如果还有其他排序,它也会在每次排序完成后显示。 对此有什么建议吗?

跟踪上一个$time1,当它发生变化时,插入<hr>

$lastTime = null;
while (/* whatever */) {
// snip
// check for null so as not to insert an <hr> for the first record
if ($lastTime != null && $lastTime != $time1) {
echo '<hr>';
}
$lastTime = $time1;
// and so on
}

最新更新