我的应用程序是关于导入excel文件,并在数据库中插入字段,除了我想在每个级别(Niveau)下面添加一行以进行求和。
我想知道如何制作
我做了一个查询,它在mysql中完美运行,但是我需要在表格底部添加一行包含值的总和
谢谢
<td><?php echo gmdate('H:i:s', $t[11]); ?></td>
<tr><?php $sql="select user, equipe, (SUM(TIME_TO_SEC(agent_time))) AS agent_time , (SUM(TIME_TO_SEC(wait))) AS wait , (SUM(TIME_TO_SEC(talk))) AS talk , (SUM(TIME_TO_SEC(dispo))) AS dispo , (SUM(TIME_TO_SEC(pause))) AS pause , (SUM(TIME_TO_SEC(dead))) AS dead , (SUM(TIME_TO_SEC(ps))) AS ps , (SUM(TIME_TO_SEC(pp))) AS pp , (SUM(TIME_TO_SEC(pb))) AS pb , (SUM(TIME_TO_SEC(pam))) AS pam , (SUM(TIME_TO_SEC(pa))) as PA , (SUM(TIME_TO_SEC(login))) AS plogin , (SUM(TIME_TO_SEC(pf))) as pf , (SUM(TIME_TO_SEC(padmin))) AS padmin , (SUM(TIME_TO_SEC(pf))) AS pf, (SUM(TIME_TO_SEC(ppan))) AS ppan from agent_time where equipe='Niveau 3' ";
$x = $conn->query($sql);
?></tr>
答案 0 :(得分:0)
对于我所看到的,您希望使用您所做的查询显示html表的最后一行(表示您的数据库表)。更简单的方法是将负责创建最后一行的函数中的行为分开如下:
function sumLastRow() {
$sql="select
user,
equipe,
(SUM(TIME_TO_SEC(agent_time))) AS agent_time ,
(SUM(TIME_TO_SEC(wait))) AS wait ,
(SUM(TIME_TO_SEC(talk))) AS talk ,
(SUM(TIME_TO_SEC(dispo))) AS dispo ,
(SUM(TIME_TO_SEC(pause))) AS pause ,
(SUM(TIME_TO_SEC(dead))) AS dead ,
(SUM(TIME_TO_SEC(ps))) AS ps ,
(SUM(TIME_TO_SEC(pp))) AS pp ,
(SUM(TIME_TO_SEC(pb))) AS pb ,
(SUM(TIME_TO_SEC(pam))) AS pam ,
(SUM(TIME_TO_SEC(pa))) as PA ,
(SUM(TIME_TO_SEC(login))) AS plogin ,
(SUM(TIME_TO_SEC(pf))) as pf ,
(SUM(TIME_TO_SEC(padmin))) AS padmin ,
(SUM(TIME_TO_SEC(pf))) AS pf,
(SUM(TIME_TO_SEC(ppan))) AS ppan
from agent_time
where equipe='Niveau 3'";
$x = $conn->query($sql);
$result = $x->fetch_object();
if ($result) {
$response = "<tr>";
$aux = "<td>%v</td>";
foreach ($result as $key => $value) {
$response .= str_replace("%v", $value, $aux);
}
$response .= "</tr>";
}
return $response;
}
之后,只需打印表格最后一行的函数返回的值。