2017-09-24 41 views
0

マイJOINテーブルJOINにのユーザーにの名前ランクSQLクエリ、別のテーブルの構文エラー

マイコード:

$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); 
+0

例のデータセットと質問から正確な出力を得てください。 – user1735921

+0

エラーは、SQLクエリについてです。OUTHER JOINの構文... –

+0

'WHERE trend = 1'はどこですか? 'trend'フィールドはどこですか? –

答えて

0

、このいずれかを試してみてください。このヘルプを期待してください

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

$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);