我想将具有相同名称的行合并到下表中的一行,并且请假计数应在合并时显示其总和,我使用了两个forach列出表,因为它获取了两种数据。 work.send作为电子邮件的邮件正文尝试了一些方法see,但是没有用
姓名假 Emp1 0 经验2 0.5 Emp3 1 Emp2 1 Emp4 4 Emp5 1 Emp3 1
代码:
$message2="<html>
<body>
<table ;>
<thead>
<tr>
<th>Name</th>
<th>Leave</th>
</tr>
</thead>
<tbody>";
foreach($leave2 as $val) {
if($val->hourcount>2)
{
$newcount=.5;
}
else
{
$newcount=0;
}
if($val->hourcount>=6)
{
$newcount=1;
}
$message2 .="<tr>
<td>" . $val->resource ."</td>
<td>".$newcount."</td>
</tr>";
}
foreach($leave as $value) {
$message2 .="<tr>
<td>" . $value->resource ."</td>
<td>".$value->Days."</td>
</tr>";
}
if (count($value->resource) > 0) {
$html = '';
foreach($val->resource as $key => $val) {
$html .= "<tr>\r\n";
$html .= "<td rowspan='".count($val)."'>{$key}</td>\r\n";
foreach($val as $key => $td) {
if($key>0) {
$html.= "<tr>";
}
$html .= "<td>{$td}</td>\r\n";
$html .= "</tr>\r\n";
}
}
}
"</tbody>
</table>
<p>Leave report</p>
<hr />
</body>
</html>";
答案 0 :(得分:1)
您可以尝试这样的事情
1)创建一个数组,其中保存员工姓名及其离职总数
2)显示该阵列中所需的表格式
<?php
$sql = "SELECT * FROM table_name";
$result = $db->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$name = $row['Name'];
$level = $row['Level'];
if(isset($leaveArr[$name])){
$leaveArr[$name] = $leaveArr[$name]+ $level;
}else{
$leaveArr[$name] = $level;
}
} }
if(count($leaveArr)>0){
echo "<table>";
echo "<tr><td>Name</td><td>Leave</td></tr>";
foreach ($leaveArr as $key => $value) {
echo "<tr>";
echo "<td>" . $key . "</td>";
echo "<td>" . $value . "</td>";
echo "</tr>";
}
echo "</table>";
}