0
我得到$ _post數組並在每次迭代上運行查詢,然後嘗試獲取累積總點數,似乎用最後一次迭代覆蓋總數。我該如何解決?從foreach循環獲取總數+ mysql while循環
$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;
從而徹底降低了$需要total_donatinos 0它不使用其他任何地方;) – ThaMe90 2013-03-07 14:55:33
是的,你」回覆右邊,我編輯答案 – rsz 2013-03-07 14:56:43
哇,我肯定我嘗試過,但它完美的作品。非常感謝! – Grant 2013-03-07 15:00:05