title: Create Array from Foreach
body: <p>I have a Mysql table which contains a column of JSON data and a column with an amount. 
  The goal is to extract the JSON data and the amount and build an array within the foreach loop. 
  Here is my code:</p>
  
  <pre><code>$sql = "SELECT `Amount`, `NewObject` FROM `mb_cart` WHERE `MyID` = '$id'";
  $data_main = $db-&gt;query($sql);
  </code></pre>
  
  <p>Here is my statement that I am using to build the array:</p>
  
  <pre><code>foreach ($data_main as $transaction_main) {
      $json_decoded = json_decode($transaction_main);
      $cart = array('Amount' =&gt; $amount, 'CodeType' =&gt; $json_decoded-&gt;data-&gt;Type-&gt;data-&gt;codeType, 'Name' =&gt; $json_decoded-&gt;data-&gt;Name, 'SiteName' =&gt; $json_decoded-&gt;data-&gt;SiteName);
  }
  </code></pre>
  
  <p>However when I run this, I am only returning only the first record set and the amount is blank, but the JSON data is listed. Appreciate any insight anyone cares to share.</p>