title: PHP - Client Selects X Quantity - Want To Grab X Quantity From Stock & Email All
body: <p>So I've been trying with this for a while now and can't seem to find the solution.</p>
  
  <p>I have a website, selling digital good.</p>
  
  <p>When the client checks out, it asks for what quantity.</p>
  
  <p>I want to make it so when they type in for example, quantity 5, I want it to grab 5 stocks from the database and send all to their email.</p>
  
  <p>I need to make it loop through and grab x quantity from a stock table where the assignedProduct is the product ID.</p>
  
  <p><strong>Currently, my code only getting the number of quantity and not getting different rows from my stock database. How do I make it loop the stock?</strong></p>
  
  <p><a href="https://i.stack.imgur.com/ngHCI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ngHCI.png" alt="Currently showing this"></a></p>
  
  <p><strong>My current code is (using blockchain payment processor):</strong></p>
  
  <pre><code>&lt;?php
  
      $smtp_btc = $pdo-&gt;prepare('SELECT * FROM `productitems` WHERE `avaliable` = :avaliable AND `assignedProduct` = :assignedProduct');
      $smtp_btc-&gt;execute(array(':avaliable' =&gt; '0', ':assignedProduct' =&gt; $product_id));
      $query = $smtp_btc-&gt;fetchAll();
  
      // Select all from stock where avaliable = true and assignedProduct is the main productID
      // Then make it 
  
      // Foreach loop here
      $i = 0;
      $maxiterations = $quantity - 1;
      $message = '';
  
      foreach($query as $row_product) {
          while($i &lt;= $maxiterations) {
              $i++;
              $product_link_stock = $row_product['code'];
              $stock_id_stock = $row_product['id'];
  
              $message = "&lt;tr style='background: #eee;'&gt;&lt;td&gt;&lt;strong&gt;Email/Username:Pass(".$i."):&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;$product_link_stock&lt;/td&gt;&lt;/tr&gt;";
              echo $message.'&lt;br&gt;';
          }
      }
  
  
  ?&gt;
  </code></pre>