1 回答

TA貢獻1850條經驗 獲得超11個贊
你可以嘗試這樣的事情:
<?php
// You create an empty array
$result = [];
while($row1 = mysqli_fetch_array($result1))
{
// I assume $row1["codigo"] is your id. If not, replace by your id.
// The idea is to fill the array with all the data you will display after
$result[$row1["codigo"]] = array(
"nome" => $row1["nome"],
"qtd1_2hora" => $row1["QTD 1o e 2o Hora"],
...
"total" => $row1["Valor Total"]
);
}
// Now the second while
while($row3 = mysqli_fetch_array($result3))
{
// If you don't have a row with the same id : create it
if (empty($result[$row3["codigo"]])) {
$result[$row3["codigo"]] = array(
"nome" => $row3["nome"],
"qtd1_2hora" => $row3["QTD 1o e 2o Hora"],
...
"total" => $row3["Valor Total"]
);
}
// Now if you already have a row with this id : update your data
else {
// Eg: if you want to add the total of first while with total of second while
$result[$row3["codigo"]]["total"] += $row3["Valor Total"];
/* You have to do what you want here, can't help you more ! */
}
}
// Now you can display you data :
foreach ($result as $id => $data) {
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $data["nome"]; ?></td>
<td><?php echo $data["qtd1_2hora"]; ?></td>
...
<td><?php echo $data["total"]; ?></td>
</tr>
<?php
}
?>
是你要找的嗎?
- 1 回答
- 0 關注
- 117 瀏覽
添加回答
舉報