gpt4 book ai didi

php - 如果价格已降低,则从 mySQL 数据库获取一行

转载 作者:行者123 更新时间:2023-11-29 20:55:52 25 4
gpt4 key购买 nike

我试图仅显示数据库中已减少设置为"is"的产品,但收到以下错误:Warning: Invalid argument supplied for foreach() in /reduced.php on line 79

减少.php

<?php
$pdo = new PDO('mysql:host=localhost;dbname','name','password');
$reduced = 'yes';
$result = $pdo->query('SELECT file_id, productName, price, stock, reduced FROM files WHERE reduced = '.$reduced.'');
foreach($result as $row){
echo "<div id='shop'>";
echo "<img id='product' src=\"file.php?id={$row['file_id']}\">";
echo '<p>' . $row['productName'] . '</p>';
echo '<p>' . "£" . $row['price'] . '</p>';
echo '<p>' . "Stock Level: " . $row['stock'] . '</p>';
echo '<a href="basket.php">ADD TO BASKET</a>';
echo "</div>";
}
?>

最佳答案

这是引号尝试

 $result = $pdo->query('SELECT file_id, productName, price, stock, reduced FROM files WHERE reduced = "'.$reduced.'"');

关于php - 如果价格已降低,则从 mySQL 数据库获取一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37632977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com