gpt4 book ai didi

php - 需要有关 mysql 错误的帮助

转载 作者:行者123 更新时间:2023-11-29 06:14:06 24 4
gpt4 key购买 nike

希望有人能帮我解决问题。这似乎是一个语法问题,但我无法确定问题到底是什么...我正在使用最新版本的 mysql

我收到此错误:

“警告:mysql_fetch_assoc() 期望参数 1 为资源, bool 值在第 14 行 C:...\testing_album_func.php 中给出”

这是我的代码:

function get_listings() { 

$listings = array();

$listings_query = mysql_query("SELECT `class_ads`.`ad_id`, `class_ads`.`created_on`,
LEFT(`class_ads`.`title`, 50) as `title`, LEFT(`class_ads`.`description`, 50) as
`description`, `class_ads`.`price`, `class_ads`.`quantity`,
COUNT(`images`.`image_id`) as `image_count` FROM `class_ads` LEFT JOIN `images` ON
`class_ads`.`ad_id`=`images`.`ad_id` WHERE `user_id`='".$_SESSION['user_id']."' GROUP
BY `class_ads`.`ad_id`");


while ($listings_row= mysql_fetch_assoc($listings_query)) {

$listings[] = array(
'ad_id' => $listings_row['ad_id'],
'created_on' => $listings_row['created_on'],
'title' => $listings_row['title'],
'description' => $listings_row['description'],
'price' => $listings_row['price'],
'quantity' => $listings_row['quantity'],
'image_count' => $listings_row['image_count']
);

}

return $listings;
}

最佳答案

mysql_query 如果出现错误,则返回 false。

您应该进行如下检查:

if(!$listings_query) {
die('An error occurred. The message is: ' . mysql_error());
}

您的 SQL 语句看起来有点奇怪,因此您还应该打印出实际的查询并确保它看起来不错。

关于php - 需要有关 mysql 错误的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7641184/

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