【发布时间】:2018-09-07 22:51:37
【问题描述】:
搜索参数后我有一个结果数组,我想打印该结果。使用 foreach 循环打印结果时,我需要检查条件,如果购买日期相同,它们应该打印在同一行中。我该如何实现这个?请帮助我。在此先感谢
这是我的代码:(我已经在控制器中得到结果,然后我将结果附加到视图中)
foreach($res as $key => $row)
{
$i++;
$billfirst='';
$billend= $row['bill_date'];
if( $billfirst != $billend){
echo "<tr>
<td class='txt'> ".$i."</td>
<td class='txt'> ".$row['store']."</td>
<td class='txt'> ".$row['cust']."</td>
<td class='txt'> ".$row['name']."</td>
<td class='txt'> ".$row['net_amount']."</td>
<td class='txt'> ".$row['bill_date']."</td>
</tr>" ;
}
else {
echo "<tr><td class='txt'> ".$row['name']."</td>
<td class='txt'> ".$row['net_amount']."</td>
<td class='txt'> ".$row['bill_date']."</td>
</tr>";
}
$billfirst == $billend;
echo "</tbody></table>";
}
【问题讨论】:
-
foreach($res as $key => $row) enter code here{?这是什么....肯定不是有效的PHP。 -
请多解释。没看清楚。你的预期结果是什么?请同时附上预期结果。
-
var_dump($res)?
标签: php html html-table