Note that there are some explanatory texts on larger screens.

plurals
  1. POGet values from HTML in a multidimensional array and calculate values using PHP
    primarykey
    data
    text
    <p>I have searched but could not get solution on this issue.</p> <p>I am working on an application which will generate unknown number of items and have users select the quantity from a drop down against each item. Eg.</p> <pre><code>Item(s) | price | Select qty Rice 23 3 Beans 22 4 Eggs 52 5 ... ... ... unknown </code></pre> <p>Please, how can I capture the above in an array and also calculate the total value for all selected items and corresponding fees?</p> <p>I have the following HTML code:</p> <pre><code>&lt;form id='form1' name='form1' method='post' action='item_calc.php'&gt; &lt;?php ..... while($t_row = mysql_fetch_assoc($get_items)) { echo "&lt;p&gt;&lt;label&gt;$t_row['$item_name'] &lt;input type='text' READONLY name='item_price[]' value='$t_row['$item_price']' /&gt;&lt;/label&gt; &lt;input type='text' READONLY name='item_fees[]' value='$t_row['$item_fee']' /&gt; &lt;select name="item_qty"&gt; &lt;option value="1"&gt; &lt;option value="2"&gt; &lt;option value="3"&gt; &lt;option value="4"&gt; &lt;option value="5"&gt; &lt;/select&gt; &lt;/p&gt;&lt;p&gt;"; } echo "&lt;label&gt;&lt;input type='submit' name='submit' value='Submit' /&gt;&lt;/label&gt;&lt;/p&gt; &lt;/form&gt;"; </code></pre> <p>Please, how can I get item_price[] + item_fees[] * item_qty for all selected items?</p> <p>This is what I have tried:</p> <pre><code>for ($i = 0; $i &lt; count($_POST['item_price']); $i++) { // Do something here with $_POST['checkbx'][$i] foreach ($_POST['item_fees'] as $tkey =&gt; $tvalue) { //echo "Key: $tkey; Value: $tvalue&lt;br&gt;"; } foreach ($_POST['item_price'] as $pkey =&gt; $pvalue) { //echo "Key: $pkey; Value: $pvalue&lt;br&gt;"; } $total = $tvalue + $pvalue; } echo $total; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload