【发布时间】:2015-03-29 11:39:26
【问题描述】:
我正在将 mysql 中的数据显示到网页表中。
代码(我正在使用 wordpress):
global $wpdb;
$Lists = $wpdb->get_results("select * from `price_record`;");
if($Lists== null)
{
echo"There is no price record yet!";
}
else
{
echo"<table class='priceTable' style='border:1px;border-collapse:collapse;'>";
echo"<thead>";
echo"<tr>";
echo"<th>Date</th>";
echo"<th>Category</th>";
echo"<th>Type</th>";
echo"<th>Price</th>";
echo"</tr>";
echo"</thead>";
echo"<tbody>";
foreach ($Lists as $List)
{
echo"<tr>";
echo"<td>".$List->Date."</td>";
echo"<td>".$List->Category."</td>";
echo"<td>".$List->Type."</td>";
echo"<td>".number_format($List->Price,2)."</td>";
echo"</tr>";
}
echo"</tbody>";
echo"</table>";
}
当前结果:
Date Category Type Price
---------------------------------
30/1 A T1 12
30/1 A T2 13
30/1 B T3 10
30/1 B T4 11
29/1 A T1 11
预期:
Date Category Type Price
---------------------------------
30/1 A T1 12
T2 13
B T3 10
T4 11
29/1 A T1 11
如何在显示表格时自动分组日期、类别和类型?谢谢你。
【问题讨论】:
-
您能否给我们您一直在处理的代码或数据库的结构,(它只是一个表还是通过一个表连接到另一个表等等)。
-
只需向我们展示您生成此输出的 php 代码
标签: php jquery mysql html-table