gpt4 book ai didi

php - 如何将标题放入 while 循环中,仅用于单个结果而不是重复结果?

转载 作者:行者123 更新时间:2023-11-29 12:13:17 25 4
gpt4 key购买 nike

Vehicle num    total_amount
TEST V 1234 500
TEST V 1234 500
TEST V 1234 500
TEST w 785 1000
TEST w 785 1000
TEST Z 589 700
TEST Z 589 700
TEST Z 589 700

但我想喜欢这个。

Vehicle num    total_amount
TEST V 1234 500
TEST V 1234 500
TEST V 1234 500


Vehicle num total_amount
TEST w 785 1000
TEST w 785 1000


Vehicle num total_amount
TEST Z 589 700
TEST Z 589 700
TEST Z 589 700

我想为每个组车辆显示上面的标题。

  <?php

#other code

$track = null;
$total = 0;

while ($fet_all = mysql_fetch_array($query_all)) :?>
<?php if ($track !== null && $track !== $fet_all['truckk_number']): ?>
<tr>
<td colspan="3">Vehicle No:</td>
<td><?php echo $track; ?></td>
</tr>
<tr>
<td colspan="3">Total:</td>
<td><?php echo $total; ?></td>
</tr>
<?php $total = $fet_all['total']; ?>
<?php else: ?>
<?php $total += $fet_all['total']; ?>
<?php endif; ?>
<tr class="accord-content even bg-gray" style="color:#698602 !important;">
<td><?php echo $fet_all['id']; ?></td>
<td><?php echo $fet_all['ownername']; ?></td>
<td><?php echo $fet_all['truckk_number']; ?></td>
<td><?php echo $fet_all['total']; ?></td>
</tr>
<?php $track = $fet_all['truckk_number']; //add this line ?>
<?php endwhile; ?>
<?php if ($total > 0): ?>
<tr>
<td colspan="3">Vehicle No:</td>
<td><?php echo $track; ?></td>
</tr>
<tr>
<td colspan="3">Total:</td>
<td><?php echo $total; ?></td>
</tr>
<?php endif; ?>

最佳答案

$v = false;
while ($row = someReadFunction()) {
if ($row["vehicle"] != $v) echo "Write header here...";
echo implode (" ", $row); // Or your preferred way to display it.
$v = $row["vehicle"];
};

关于php - 如何将标题放入 while 循环中,仅用于单个结果而不是重复结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30300271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com