我已经为 PDO while 循环尝试了几种不同的版本,但它们都没有返回超过一行。问题在于循环中对dreamyPrizes 表的调用。如果我把它拿出来,它工作正常,它只返回一行。
我试过了:
$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)); ?>