1
I이 사용자가 연결된 먹으 렴 모든 게시물을 반환하는 다음 쿼리 (이것은 큰 노력)MySQL의 쿼리
예를 들어
//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
절이 될 곳 :
wallcomments.tagedpersons LIKE '%".$user_id."%'
이 각 게시물에 대한 여러 의견이 있고 내가 이것을 구현하는 것이 방법 일을 고민하고, INNER JOIN을 사용합니까?
편집 : 의견에있는 글이 필요하지 않은 검색어의 게시물 만 필요합니다. 그래서 게시물의 주석에 태그가 포함되어 있으면 쿼리에 게시물이 포함됩니다.
도움이되었거나 도움이 되었으면 좋겠습니다.
SELECT 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
INNER JOIN wallusers
ON wallposts.userid = wallusers.mem_id // LOOK IF wallusers.mem_id is same as wallposts.userid , im not sure about your table
INNER JOIN wallcomments
ON wallposts.p_id = wallcomments.post_id
WHERE (wallusers.mem_id IN (".$matches.") OR wallusers.mem_id =".$user_id." OR wallposts.tagedpersons LIKE '%".$user_id."%') and wallusers.mem_id = wallposts.userid AND wallcomments.tagedpersons LIKE '%".$user_id."%'
ORDER BY wallposts.p_id,wallposts.type,wallposts.value,wallposts.media,wallposts.youtube,wallposts.post_type,wallposts.tagedpersons,wallposts.title
LIMIT ".$show_more_post.", 10
이 예상 작동하지 않습니다 같이 – Codded
이 오류가 발생합니다. # 1054 - 'on clause'의 'wallposts.p_id'알 수없는 열 – Codded
내 편집이 유창한 지 봅니다. –