【发布时间】:2021-04-16 17:13:03
【问题描述】:
我有一个显示发票及其创建日期的简单表格。我正在寻找一种在显示表格时在每个月的最后一行底部显示总发票值的方法。
例子:
| Date | Amount |
|---|---|
| 04-05-2020 | $50 |
| 02-05-2020 | $30 |
| 14-05-2020 | $10 |
| TOTAL | $90 |
| Date | Amount |
|---|---|
| 04-07-2020 | $15 |
| 02-07-2020 | $15 |
| 14-07-2020 | $15 |
| TOTAL | $45 |
有什么想法吗?这是我目前所拥有的:
<!DOCTYPE html>
<html>
<head>
<title>FACTURAS</title>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$server = "localhost";
$user = "root";
$password = "";
$db = "facturas";
$conn = new mysqli($server, $user, $password, $db);
if ($conn->connect_error) {
die("CONNECTION ERROR " . $conn->connect_error);
}
$sql = "SELECT * FROM facturas_table ORDER BY id";
$facturas = $conn->query($sql);
echo '<table>
<thead>
<tr>
<td>ID</td>
<td>DATE</td>
<td>INVOICE</td>
<td>PRICE</td>
</tr>
</thead>';
while ($row = $facturas->fetch_assoc()) {
$month = substr($row['fecha'], 3);
// $totalMonths = "SELECT SUM(monto) as montoTotal FROM facturas_table WHERE fecha = ''"
echo '
<tbody>
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['fecha'].'</td>
<td>'.$row['factura'].'</td>
<td>'.$row['monto'].'</td>
</tr>
</tbody>';
}
echo '</table>';
?>
</body>
</html>
【问题讨论】:
-
跟mysqli有什么关系?
-
确保只发布代码的相关部分 - 即 html 标题和样式真的无关紧要
-
什么究竟不能使用所有这些代码?你有什么努力让它发挥作用?
标签: php mysqli html-table