gpt4 book ai didi

php - 警告 : mysql_fetch_object(): supplied argument is not a valid MySQL result resource in json

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

我的 json 代码中有一个错误,如下所示。

错误:

警告:mysql_fetch_object():提供的参数不是第 15 行 D:\XAMPP\xampp\htdocs\ROOPA\music\demo.php 中的有效 MySQL 结果资源{“结果”:空}

PHP 文件:

<?php

@include("db.php");


$query = "SELECT a.a_name as name,b.total_value as value,b.total_votes as votes,a.a_pic as image FROM _album a inner join ratings b on b.a_id=a.id";

$result = mysql_query($query);

// $query1 = "SELECT total_value,total_votes FROM ratings";

//$result1 = mysql_query($query1);

$count = mysql_num_rows($result);
//$count1 = mysql_num_rows($result1);

if($count > 0)
{

while($data = mysql_fetch_object($result))
{
$alb_name =$data->name;

$rate_value = $data->value;

$rate_votes = $data->votes;

$alb_pic =$data->image;

$resmsg[] = array("Album_name"=>$alb_name,"Rating_total_value"=>$rate_value,"Rating_total_votes"=>$rate_votes,"Image_name"=>$alb_pic);

}

$jsonarr = array("result"=>$resmsg);
}
else
{
$jsonarr = array("result"=>"data not found");
}

echo json_encode($jsonarr);

?>

我的 DB.PHP 文件:

<?php

$hostname="localhost";
$username="root";
$password="";
$database="musicalbum";

$conn=mysql_connect($hostname,$username,$password,$database);
$link=mysql_select_db($database,$conn);

if (!$link) {
die('Could not connect: ' . mysql_error());
}
@mysql_close($link);

?>

有人可以帮助我吗?

最佳答案

我认为问题在查询的以下部分:

inner join ratings b on b.a_id=a.id"

根据您的查询,我猜测 a_[some_text] 是表 a 的列,但您的查询连接表 b 中的 a_id 。我想,应该是这样的:

inner join ratings b on a.a_id=b.id"

关于php - 警告 : mysql_fetch_object(): supplied argument is not a valid MySQL result resource in json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19153675/

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