0

hello guys am creating site were all users can post for there friends to see ans coment just like facebook where am having problem is how to make sure only a users friends can see there post not the whole site members i have table in my database called post where all post are queried from and displayed on the page according to there date of post i dnt know how to remove the post of non friends from being visible to every one just the way facebook is thanks

4
Contributors
6
Replies
28
Views
3 Years
Discussion Span
Last Post by isaac.iji.5
0

Well it is difficult to answer properly without seeing what you have done so far but I would have a friends table that will hold the ids of users with related ids of their friends and then you can just cross reference that table to match friend ids with user ids stored with your posts

Edited by simplypixie

1

Sorry but I don't want to download your code and go through it all - I want you to post the relevant sections of code on here

1

Given:
1) You have a column named 'friend_ids' which contains a comma-separated list of friend IDs, like so: "1378,1892,461,1781".
2) Your posts table uses user_id as a column to identify who made the post.
3) You have a local variable named $user_id that holds the id of the current user

Here's an example of a query to fetch only posts belonging to friends of the current user:

SELECT * FROM posts WHERE user_id IN(SELECT friend_ids FROM users WHERE user_id=$user_id)

Edited by Lsmjudoka

1

Re: simplypixie's comment

Agreed: in order to make this thread useful for anybody else with a similar query, please post your code here. Asking contributors to download an 'untrusted' file is asking too much. Posting your SQL tables and php manipulation code along with any current html forms would be useful.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.