title: Assign data from a DB to variables for shopping cart
body: <p>I want to make a shopping cart using php. First I get data from sql DB table and then add them to a array.Now I want to add these data to a html table.Each row contain a button called 'Add TO Cart'. When I click any button('Add To Cart') only the last item of the array will be added the cart array.What should I do.</p>
  
  <pre><code>$query = "SELECT * FROM `item` WHERE 1";
  
  $result = mysqli_query($con,$query);
  $k = mysqli_num_rows($result);
  $row_array;
  while($test_row = mysqli_fetch_array($result)){
      $row_array[]=$test_row;
      [enter image description here][1]
  }
  foreach($row_array as $key=&gt;$value){
      echo "&lt;tr&gt;";
          echo "&lt;td&gt;";
              echo $row_array[$key]['item_id'];
              echo '&lt;input type="hidden" name="item_id" value="' . $row_array[$key]['item_id'] . '" /&gt;';
          echo "&lt;/td&gt;";
  
          echo "&lt;td&gt;";
              echo $row_array[$key]['item_name'];
  
          echo "&lt;/td&gt;";
  
          echo "&lt;td&gt;";
              echo $row_array[$key]['item_category'];
  
          echo "&lt;/td&gt;";
  
          echo "&lt;td&gt;";
  
          echo $row_array[$key]['item_price'];
              echo '&amp;nbsp &amp;nbsp &amp;nbsp&lt;input type = "submit" name = "add_to_cart" class = "btn btn-success" value = "Add to cart" /&gt;';
          echo "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  }`
  </code></pre>