我只想查看我朋友的帖子,但收到的是来自所有用户。我不想在我的查询中为friend_array使用单独的表。
以下是我的帖子示例数据:
id body date_added added_by user_posted_to
1 whats up 2015-09-12 Francis 2pac
2 update 2015-09-12 Cate Cate
3 my life 2015-09-12 Cate 2pac
以下是我的用户示例数据:
id username first_name last_name email password sign_up_date activated bio profile_pic friend_array closed
1 Paul Paul Kent paul@yahoo.com 894416aea718e7c44a126581dd017588 2015-08-18 0 hello C2LTjo79O4I63Gt/004.jpg Cate,Mike,Grace Yes
2 Christine Christine Monica monica@gmail.com 894416aea718e7c44a126581dd017588 2015-08-18 0 welcome 3mlbDJSXoThHvEi/023.jpg Paul,Andrew,Jacob no
这是我的代码:
//If the user is logged in
$getposts = $mysqli->query("
SELECT * FROM posts
INNER JOIN users
ON FIND_IN_SET(posts.added_by, users.friend_array)
ORDER BY date_added DESC LIMIT 100")
or die(mysqli_error($mysqli));
while ($row = mysqli_fetch_assoc($getposts)) {
$id = $row['id'];
$body = $row['body'];
$date_added = $row['date_added'];
$added_by = $row['added_by'];
$user_posted_to = $row['user_posted_to'];