title: How to use arrays to store values fetch from sql query in php
body: <p>What I want to do here is to be able to assign the values from sql query into arrays.
  And then compute for the total.</p>
  
  <pre><code>&lt;?php
  
  include('conn.php');
  
  $qreports=query_database("SELECT S_PRICE, PID, QTY_PUR, ITEM_ID, CUSID, CNUM, Cust_Name, TDATE  FROM prod_table, customer_credit, sales_trans_items WHERE prod_table.PID=sales_trans_items.ITEM_ID AND sales_trans_items.CNUM=customer_credit.CUSID AND sales_trans_items.TDATE='2011-02-06 09:14:09'","onstor",$link);
  
  $grandtotal=0;
  
  $customer="";
  while($qrep=mysql_fetch_assoc($qreports)){
  
  
      $pid=$qrep['PID'];
  
      foreach ($pid as $k =&gt; $v) {
      $sids=$v;
      $qtypur=$qrep['QTY_PUR'][$k];
      $sprice=$qrep['S_PRICE'][$k];
      $customer=$qrep['Cust_Name'][$k];
      $tdate=$qrep['TDATE'][$k];
  
  
      $stot=$qtypur * $sprice;
  
      $grandtotal =$grandtotal + $stot;
  }
  
  }
  
  echo "Customer: ". $customer."&lt;br/&gt;";
  echo "Profit: ". $grandtotal;
  </code></pre>
  
  <p>?> </p>
  
  <p>I tried the query on phpmyadmin before I place it in the code, and it output this:
  <img src="https://i.stack.imgur.com/IdPcC.png" alt="enter image description here"></p>