title: Place mysql results in an array
body: <p>I have a table that contains the name of the products and their corresponding quantity.</p>
  
  <pre><code>Product      Quantity      Delete
    A             10          Del
    B              5          Del
  </code></pre>
  
  <p>What I want to do is to place them in an array with the corresponding id of the product. I can get the product ID of the second product but I cannot get the ID of the first product. How can I fix it? </p>
  
  <p>Here's the input form to the php code:    </p>
  
  <pre><code>&lt;table&gt; 
     &lt;tr&gt;
         &lt;td&gt;&lt;input id="product1" type="text" value="A" name="product1"&gt;&lt;/td&gt;
         &lt;td&gt;&lt;input id="quantity1" type="text" value="10" name="quantity1&gt;
             &lt;input type='hidden' name='htmlrow[]' value='1'&gt; &lt;/td&gt; //row number
     &lt;/tr&gt;
     &lt;tr&gt;
         &lt;td&gt;&lt;input id="product2" type="text" value="B" name="product2"&gt;&lt;/td&gt;
         &lt;td&gt;&lt;input id="quantity2" type="text" value="5" name="quantity2"&gt;
             &lt;input type='hidden' name='htmlrow[]' value='2'&gt;&lt;/td&gt;//row number
     &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>php code:</p>
  
  <pre><code>$numberOfRows = $_POST["htmlrow"];
  $r = end($numberOfRows);
  for($i=1; $i&lt;$r+1; $i++){  //r = number of rows
      $results = $wpdb-&gt;get_results("SELECT * FROM wp_products WHERE productName = '".$_POST["product".$i]."'");     
  
         foreach($results as $product){
                $pID = $product-&gt;productID;
         } //I can only get the last product ID
  
         $orderItem = array(
                          'product' =&gt; $_POST["product".$i],
                          'productID' =&gt; $pID,
                          'quantity' =&gt; $_POST["quantity".$i]
                       );
  
         $order[] = $orderItem;
    }
  </code></pre>