我已經嘗試了幾個不同版本的PDO while while循環,並沒有一個返回多個行。問題在於呼叫循環中的dreamyPrizes表。如果我把它拿出來,它可以正常工作,它只會返回一行。PDO while循環只返回一行
我想:
$st = $db->prepare("SELECT * FROM `dreamyAuctions` WHERE `showOnHomePage` =:yes AND `active`=:yes AND `completed`=:no ORDER BY `StartDate`"); // need to filter for next auction
$st->bindParam(':yes', $yes); // filter
$st->bindParam(':no', $no); // filter
$st->bindParam(':gameId', $gameId); // filter
$yes=1;
$no=0;
$st->execute();
$r = $st->fetch(PDO::FETCH_ASSOC);
<?
while($r = $st->fetch(PDO::FETCH_ASSOC)){?>
<?
$auctionId= $r['id'];
$startDate = date("m-d-Y h:i A", strtotime($startDate));
if (strlen($title) > 100)
$title = substr($title, 0, 90) . '...</a>';
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$st = $db->prepare("SELECT * FROM `dreamyPrizes` WHERE `id`=:prizeId"); // need to filter for next auction
$st->bindParam(':prizeId', $prizeId); // filter
$st->execute();
$r = $st->fetch(PDO::FETCH_ASSOC);
$prizeImage= $r['image1'];
$retailPrice= $r['retailPrice'];
?>
<div>div to loop</div> <? }?>
我也試過
do {
$auctionId= $r['id'];
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$st = $db->prepare("SELECT * FROM `dreamyPrizes` WHERE `id`=:prizeId"); // need to filter for next auction
$st->bindParam(':prizeId', $prizeId); // filter
$st->execute();
$rs = $st->fetch(PDO::FETCH_ASSOC);
$prizeImage= $rs['image1'];
$retailPrice= $rs['retailPrice'];
?>
<div>div to loop</div>
<?php } while ($r = $st->fetch(PDO::FETCH_ASSOC)); ?>
1.第一個查詢中擺脫無用的參數進行輸出。使用JOIN將它全部用** 1 **查詢。 3. **總是**在你的腳本中有'error_reporting(E_ALL)' –