我的json代码中出现了错误,。
ERROR:
警告:mysql_fetch_object():提供的参数不是第15行的D:\ XAMPP \ xampp \ htdocs \ ROOPA \ music \ demo.php中的有效MySQL结果资源 {“result”:null}
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);
?>
任何人都可以帮助我吗?
答案 0 :(得分:0)
我认为问题的下面部分存在问题:
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"