title: PHP foreach loop and add values to mysql table
body: <p>I have an array ($array) which is structured like that:</p>
  <pre><code>[auctions] 
         (         
           [0] 
                ( 
  
                  [item]
                          (
                             [id] =&gt; 45422
                          )
  
                  [quantity] =&gt; 22
                  [buyout] =&gt; 40
                  [bid] =&gt; 25
                )
  
             [1] 
                ( 
                  [item]
                           (
                             [id] =&gt; 24555
                           )
  
                  [quantity] =&gt; 85
                  [buyout] =&gt;120
                  [bid] =&gt; 58
                )
  
             [2]
           ....
  </code></pre>
  <p>I want to store some of these values in a mysql table. Additionally I want a timestamp and if the <code>item-&gt;id</code> already exists in my table (as the primary key) the other values should just get updated.</p>
  <pre><code>[item] -&gt; [id]
  [quantity]
  [buyout] 
  TIMESTAMP
  </code></pre>
  <p>I tried it like that:</p>
  <pre><code> foreach ($array['auctions'] as $auctiondata) {
  
   $sql =&quot;INSERT INTO `blackrock` (`item_id`, `actual_prices`, `actual_quantity`, `last_update`) VALUES ('&quot;. $auctiondata['item']['id'].&quot;', '&quot;. $auctiondata['buyout'].&quot;', '&quot;. $auctiondata['quantity'].&quot;', 'CURRENT_TIMESTAMP')
     ON DUPLICATE KEY UPDATE item_id='&quot;. $auctiondata['item']['id'].&quot;', '&quot;. $auctiondata['buyout'].&quot;', '&quot;. $auctiondata['quantity'].&quot;'&quot;;
  
   }
  </code></pre>