title: Add variables separated by an argument
body: <p>I am trying to design this so that I can add up each group separately. Currently Quantity Total and Sum Total are giving me the sum of all of the items altogether rather than the variables in each section.</p>
  
  <p>For example, if $maxinv is equal to 5, then it will display five tables and the amount in the first one will be correct but then it will add up the total of each additional table after that. But I need to display the respective totals of each.</p>
  
  <p>Any help would be appreciated.</p>
  
  <pre><code>$masterquery = mysql_query("SELECT * FROM `inventory_master` WHERE `jobid`='$jobid' ORDER BY invtotal ASC");
  $maxinvquery = mysql_query("SELECT MAX(invtotal) AS `totalinv` FROM `inventory_master` WHERE `jobid`='$jobid'");
  
  
  $number=2;
  while ($maxinv&gt;=$number){
      echo '&lt;div class="tab-pane" id="'.$number.'"&gt;&lt;table class="table"&gt;&lt;thead&gt;&lt;th&gt;Item type&lt;/th&gt;&lt;th&gt;Item description&lt;/th&gt;&lt;th&gt;Cost per unit&lt;/th&gt;&lt;th&gt;Item quantity&lt;/th&gt;&lt;th&gt;Total price&lt;/th&gt;&lt;/thead&gt;';
      $q=0;
      while($inventorynumber&gt;$q){
          if ($invtotal[$q]==$number){
              $invdate=$date[$q];
              $item_total = (($quantity[$q])*($price[$q]));
              $quantities = $quantity[$q];
              echo '&lt;tr&gt;&lt;td&gt;&lt;a&gt;'.$item[$q].'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a&gt;'.$desc[$q].'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;$&lt;a&gt;'.$price[$q].'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a&gt;'.$quantity[$q].'&lt;/a&gt;&lt;/td&gt;&lt;td&gt;$'.$item_total.'&lt;/td&gt;&lt;/tr&gt;';
              $sum_total += $item_total;
              $quantity_total += $quantities;
              $q++;
          }
          else{
              $q++;
          }
      }
  
      echo '&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Added '.$invdate.'&lt;/strong&gt;&lt;/td&gt;&lt;td colspan="2"&gt;&lt;/td&gt;&lt;td&gt;&lt;h3&gt;'.$quantity_total.' items&lt;/h3&gt;&lt;/td&gt;&lt;td&gt;&lt;h3&gt;Total = '.$sum_total.'&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;';
      $number++;
  </code></pre>