我已经在这个问题上停留了一段时间,似乎无法弄清楚。
我正在以整数形式运行数量,例如5。
我想遍历每个数量,直到达到最大数量为止,最大是他们从0开始输入的数量。
这是我要查询的股票项目:
$product_id = '1';
$quantity = '2';
$smtp_main = $pdo->prepare('SELECT * FROM `productitems` WHERE `avaliable` = :avaliable AND `assignedProduct` = :assignedProduct LIMIT :limit');
$smtp_main->execute(array(':avaliable' => '0',':assignedProduct' => $product_id,':limit' => $quantity));
$query = $smtp_main->fetchAll();
这是我当前的while循环/ foreach循环:
// Foreach loop here
$i = 0;
$maxiterations = $quantity;
while($i <= $maxiterations) {
foreach($query as $row_product) {
$product_link_stock = $row_product['code'];
$stock_id_stock = $row_product['id'];
}
$message .= "<tr style='background: #eee;'><td><strong>Email/username:Pass(".$i."):</strong> </td><td>".$product_link_stock."</td></tr>";
$i++;
// Update stock foreach stock product they require (quantity depends on this)
$updateStock = $pdo->prepare('UPDATE `productitems` SET `avaliable` = :avaliable WHERE `id` = :id');
$updateStock->execute(array(':avaliable' => '1',':id' => $stock_id_stock));
}
然后我的邮件功能不在两个循环中,并且它可以毫无问题地发送邮件。