2 回答

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個贊
您不能將else與foreach一起使用,因此需要在使用foreach語句之前檢查是否有任何結(jié)果。
if($stmt->rowCount() > 0) {
foreach($stmt as $row)
{
$output = echo"
<div class='product_wrapper'>
<form method='post' action=''>
<table style='width:170px;height:143px;''>
<tr>
<td><input type='hidden' name='productCode' value=". $row['productCode']." />
<div class='name'>".$row['productName']."</div>
<div class='price'>RM". $row['MSRP']."</div></td>
</tr>
<table style='width:170px;height:60px'>
<tr>
<td><button type='submit' class='buy' style='margin: : 25px;'>Buy Now</button></td>
</tr>
</table>
</table>
</form>
</div>";
$output;
}
} else {
echo 'Data Not Found';
}

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個贊
您可以rowCount用來獲取受影響的行數(shù)
試試這個
if($stmt->rowCount() > 0) {
//Loop throught the rows
}else{
echo "No matching records found.";
}
檢查更多信息PDOStatement :: rowCount
- 2 回答
- 0 關(guān)注
- 157 瀏覽
添加回答
舉報(bào)