SQL查询,JOIN另一个表语法错误

时间:2017-09-24 09:04:45

标签: php mysql arrays

我的桌子:

内容:content_id,publisher_id,标题,类别,趋势

用户:ID,姓名,等级

我想加入用户并获取名称排名

我的代码:

$query = $conn->prepare
     ("select * from contents 
     FULL OUTER JOIN users ON contents.publisher_id = users.id 
     WHERE trend =1 order by content_id desc limit 20");
$query->execute(array());

};

$data = array();
while($result= $query->fetch(PDO::FETCH_ASSOC)) {
$data[] = array("content_id"    =>$result['content_id'], 
                "publisher_id"  =>$result['publisher_id'],
                "publisher_name"=>$result['name'],
                "publisher_rank"=>$result['rank],
                "title"         =>$result['title'],
                "category"      =>$result['category'],
                "type"          =>$result['type']
                );

};
echo json_encode($data);

1 个答案:

答案 0 :(得分:0)

试试这个。希望这个帮助

{{1}}