ユーザーが関連付けられているすべての投稿を返す次のクエリがあります (これはうまく機能しています)
例えば
//friends
wallusers.mem_id IN (".$matches.")
// themselves
OR wallusers.mem_id =".$user_id."
//tagged in
OR wallposts.tagedpersons LIKE '%".$user_id."%'
$qry = "SELECT DISTINCT wallposts.p_id,wallposts.type,wallposts.value,wallposts.media,wallposts.youtube,wallposts.post_type,wallposts.tagedpersons,wallposts.title AS thetitle,wallposts.url,wallposts.description,wallposts.cur_image,wallposts.uip,wallposts.likes,wallposts.userid,wallposts.posted_by,wallposts.post as postdata,wallusers.*, UNIX_TIMESTAMP() - wallposts.date_created AS TimeSpent,wallposts.date_created
FROM wallposts,wallusers
where (wallusers.mem_id IN (".$matches.") OR wallusers.mem_id =".$user_id." OR wallposts.tagedpersons LIKE '%".$user_id."%') and wallusers.mem_id = wallposts.userid
order by wallposts.p_id desc
limit ".$show_more_post.", 10";
このクエリにコメントを追加して、誰かがコメントでユーザーにタグを付けると、このクエリで返されるようにします。
これは次のように結合されます:
wallposts.p_id = wallcomments.post_id
where句は次のようになります。
wallcomments.tagedpersons LIKE '%".$user_id."%'
各投稿には複数のコメントがあり、これをどのように実装するかを考えるのに苦労しています.INNER JOINを使用しますか?
編集: クエリに投稿が必要なだけで、コメントはそこにある必要はありません。したがって、投稿のコメントにタグ付けされている場合は、投稿をクエリに含めます。
ヘルプ/ガイダンスをいただければ幸いです。