title: Inserting MySQL table data into a PHP array
body: <p>I've been working on a website for a business that I own and I'm a bit rusty on my PHP and SQL. I was able to create a mock up shop / inventory array of what I want in PHP, but I am hung up on attempting to insert table data from a MySQL database into my PHP array. What I am trying to do is duplicate my mock up, however, rather than pulling from a defined array (s) in my <code>inventoryArray.php</code>, I'd like to pull data from a table I created in MySQL.</p>
  
  <p>The mock up is as follows:</p>
  
  <p>shop.php (current):</p>
  
  <pre><code>&lt;?php foreach ($inventory as $handgun) {?&gt;
      &lt;div class="column"&gt;
          &lt;h5&gt;&lt;?php echo "$handgun[model]"?&gt;&lt;/h5&gt;
          &lt;img class="thumbnail"
              src="assets/style/images/inventory/pistols/&lt;?php echo "$handgun[img]" ?&gt;.png"&gt;
          &lt;table class="shopTables"&gt;
              &lt;tr&gt;
                  &lt;th&gt;MPN:&lt;/th&gt;
                  &lt;td&gt;&lt;?php echo "$handgun[mpn]"?&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;UPC:&lt;/th&gt;
                  &lt;td&gt;&lt;?php echo "$handgun[upc]"?&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;Accessories:&lt;/th&gt;
                  &lt;td&gt;&lt;?php echo "$handgun[accessories]"?&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th&gt;Description:&lt;/th&gt;
                  &lt;td&gt;&lt;?php echo "$handgun[description]"?&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;a href="product-page.php" class="button expanded"&gt;View&lt;/a&gt;
      &lt;/div&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>inventoryArray.php (before):</p>
  
  <pre><code>    &lt;?php
      $inventory = array(
           array(
               'action'        =&gt; "Striker-fired",
               'category'      =&gt; "Pistols",
               'cal_ga'        =&gt; "9mm",
               'manufacturer'  =&gt; "FN Herstal",
               'model'         =&gt; "FN 509 Midsize",
               'UPC'           =&gt; "845737010010",
               'img'           =&gt; "FN509M",
               'price'         =&gt; "$649"
           ),
           array(
               'action'        =&gt; "SA/DA",
               'category'      =&gt; "Pistols",
               'cal_ga'        =&gt; "9mm",
               'manufacturer'  =&gt; "CZ USA",
               'model'         =&gt; "CZ P01",
               'UPC'           =&gt; "806703911991",
               'img'           =&gt; "CZP01",
               'price'         =&gt; "$627"
           )
       );
      ?&gt;
  </code></pre>
  
  <p>I did not change anything from <code>shop.php</code>, the following is my attempt at using data from my MySQL table in my <code>inventoryArray.php</code> file:</p>
  
  <p>inventoryArray.php (after):</p>
  
  <pre><code>require_once ('../mysqli_connect.php');
  $query = "SELECT * FROM firearms";
  
  $response = @mysqli_query($dbc, $query);
  while ($row= mysqli_fetch_array($response)) {
      $inventory = array(
          array(
              'model' =&gt; $row['model'],
              'img' =&gt; $row['img'],
              'mpn' =&gt; $row['mpn'],
              'upc' =&gt; $row['upc'],
              'accessories' =&gt; $row['accessories'],
              'description' =&gt; $row['description']
          )
      );
  }
  
  mysqli_close($dbc);
  </code></pre>
  
  <p>Though this inserts data from my table and into my array, inserting new inventory into my SQL table will not create a newly nested array similar to my mock-up. Instead, it seems to overwrite the original array.</p>