我的html表结构如下
name |1-2018-count |1-2018-fee |2-2018-count |2-2018-fee ..
--------------------------------------------------------------------
xyz |2 | 200 |3 |50
xyz |1 | 230 |2 |350
abc |7 | 800 |1 |50
abc |2 | 100 |1 |100
abc |2 | 100 |3 |150
但是现在我想根据第一列显示计数和费用的总和
name |1-2018-count | 1-2018-fee |2-2018-count |2-2018-fee ..
--------------------------------------------------------------------
**xyz |3 | 430 |5 |400**
xyz |2 | 200 |3 |50
xyz |1 | 230 |2 |350
**abc |9 | 1000 |5 |300**
abc |6 | 800 |1 |50
abc |2 | 100 |1 |100
abc |1 | 100 |3 |150
我不知道该怎么做。
请任何建议。
我从php生成html,然后ajax请求获得响应。
public function buildHtmlTablemonthly($sql){
$table = "";
$table .= "<table border='1' id='reportTable'><thead><tr>";
$arr = [];
foreach ($sql[0] as $key => $value) {
$table .= "<th class='text-center' style='width:130px '>" . $key . "</th>";
}
$table .= "</tr></thead><tbody>";
foreach ($sql as $a) {
$table .= "<tr>";
$i = 0;
foreach ($a as $key => $value) {
$colspan = ($i != 0) ? " colspan='1'" : "";
if ($value == null) {
$val = "-";
} else {
$val = $value;
}
}
$table .= "<td class='text-left ".$key."' style='width:130px'" . $colspan . ">" . $val . "</td>";
$i++;
}
$table .= "</tr>";
}
$table .= "</tbody></table>";
return $table;
}