By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Calc total of dynamic field

P: 1
hello, i'm trying to make a sum of the values find in " total3$id" but i'm sure how to do id....

Expand|Select|Wrap|Line Numbers
  1.                             <?php
  2.  
  3.                     $query="SELECT * from photo";
  4. $result = mysql_query($query) or die(mysql_error());
  5. $calcTotal = array();
  6.  
  7. while($row = mysql_fetch_array($result))
  8. {
  9.  
  10. $prezzoaccconvirgola=str_replace('.', ',', $row['prezzoacc']);
  11. $balance=$row['piante_pianali'];
  12. $allotment=$row['piante_pianali'];
  13. $total = $balance*$allotment;
  14. $prezzo=$row['prezzoacc'];
  15. $piante_cc=$row['piante_cc'];
  16. $total2 = $allotment*$total;
  17. $id=$row['id'];
  18. $calcTotal[$id] = $total;
  19. $calcTotal2[$id] = $total2;
  20. $calcTotal3[$id] = $total3;
  21. $calcTotal4[$id] = $total4; //stores each calculated total as array element with key of 'id'
  22. echo  "
  23.  
  24.     <input type='hidden' value='$balance' name='balance$id'>
  25.     <input type='hidden' value='$prezzo' name='prezzo$id'>
  26.     <input type='hidden' value='$piante_cc' name='piante_cc$id'>
  27.     <input type='hidden' value='$total3$id' name='total3$id'>
  28.                                         <td>".$row['prodotto']."</td>
  29.                                         <td>".$row['piante_pianali']."</td>
  30.                                         <td>".$row['piante_cc']."</td>
  31.                                         <td>".$prezzoaccconvirgola."</td>
  32.                                     <td><input type='number' name='allotment$id' size=8 onchange='total$id.value = ((allotment$id.value) * (balance$id.value)); total2$id.value = ((((allotment$id.value) * (balance$id.value) * (prezzo$id.value)) * 100 )/100); total3$id.value = (((allotment$id.value) * (balance$id.value)) / (piante_cc$id.value)) ; '></td>
  33.                                     <td><input type='number' value='$ThisTotal' name='total$id' align='right' size=8 readonly></td>
  34.                                     <td><input type='number' name='total2$id' align='right' size=8 readonly></td>
  35.                                     <td><input type='text' class='qty1' name='total3$id' align='right' size=8 readonly></td>
  36.  
  37.                                         </tr>
  38.  
  39.                                             ";
  40.  
  41.                                      }
  42.  
  43. ?>
  44.  
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


rollerbladegirl
P: 69
If I my suggest:

A little bit of basic math examples
https://www.homeandlearn.co.uk/php/php2p6.html

A little bit more than that
https://www.php.net/manual/en/functi...ber-format.php

A little bit of using PHP array_sum() Function
https://www.w3schools.com/Php/func_array_sum.asp

Calculating the sum of values in an array
https://www.php.net/manual/en/function.array-sum.php

I hope that helps.
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.