我正在获取 $_post 数组并在每次迭代时运行一个查询,然后尝试获取累积的总点数,它似乎用最后一个点迭代覆盖了总数。我该如何解决?
$full_total = 0;
foreach($postid as $key => $value){
$array = explode(',', $value);
if($value[0]!=''){
$id = $array[0];
$query = "SELECT * FROM products WHERE id = '$id'";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)) {
echo '<tr valign="bottom">';
echo '<td>' . stripslashes($row['rangeCode']) . '-' . stripslashes($row['pointsType']) . '</td>';
echo '<td>' . stripslashes($row['category']) . '</a></td>';
echo '<td>' . stripslashes($row['itemDesc']) . '</a></td>';
echo '<td class="middle">' . stripslashes($row['points']) . '</a></td>';
echo '</tr>';
$total_donations = $row['points'];
}
}
}
$full_total += $total_donations;
echo $full_total;