dongxia9620 2015-12-08 03:39
浏览 124

PHP / HTML获取多个数组并存储到数组中以进行总结

I have a form here, I have set the checkbox value to that of the respective pricing of that product. The textbox is for users to key in the quantity they want. In my PHP file, then I would compute the total amount submitted in an order form but I can't seem to get it right. The name of my checkboxes is "prodID[]" and that of my textboxes is "prodQty[]". The code below is what I have done in my php file.

echo '<td width="200px"><input name="prodID[]" id="'.$row['prodAmt'].'" type="checkbox" value="'.$row['prodAmt'].'">';      
echo '<input name="prodQty[]" type="hidden" value="0"><input name="prodQty[]" id="'.$row['prodID'].'" type="text" size="1" value="" >';

enter image description here

$orderQty[] = $_POST['prodQty'];
$orderAmt[] = $_POST['prodID'];

for ($i=0; $i < count($orderQty); $i++) {
    $multiple[$i]=$orderQty[$i]*$orderAmt[$i];
}
$amount = array_sum($multiple);
  • 写回答

1条回答 默认 最新

  • dsedug8644 2015-12-08 03:47
    关注

    Why not just add it while looping?

     $multiple+=$orderQty[$i]*$orderAmt[$i];
    
    评论

报告相同问题?