因此编写了我的第一个带有网上商店的 PHP 网站。我写了一段代码,假设选择包含一个类别的所有产品的产品数据库,然后使用相同的 product_id
选择前面的图片显示图像。
代码如下:
<?PHP
include_once "db.php";
$result = "(select * FROM products WHERE product_type = 'weddingdressaline') inner join (select * FROM images WHERE postion = 'front') images on products.product_id = images.product_id";
while($row = mysql_fetch_array($result)) {
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
echo $row['price'];
}
mysql_free_result($result);
mysql_close();
?>
但是当我运行脚本时出现以下错误:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in **/weddingdressaline.php on line 4
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in **/weddingdressaline.php on line 11
现在我很确定第二个错误的原因是因为第一个错误正在发生。如果您能给我任何帮助,我将不胜感激。
最佳答案
您没有将查询发送到 SQL 数据库 - 它只是一个字符串。您需要对其调用 mysql_query
,如下所示:
$result = mysql_query("(select * FROM products WHERE product_type = 'weddingdressaline') inner join (select * FROM images WHERE postion = 'front') images on products.product_id = images.product_id");
不过,正如 Pekka 指出的那样,您也应该检查错误。
关于PHP 错误 : "supplied argument is not a valid MySQL result resource in",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8288974/