Jump to content

[php] Bit confused with a query


JonnySnip3r

Recommended Posts

Hey guys i have been making a site that allows people to make friends and make posts on each walls a majority is done now but when i came to do the posting on walls i have hit one cause i cant figure out the query i will need for such a pretty complex task.

 

It works like this i have a friends table and a topics table each something like this::

 

member_topics << Name

topic_id

member_id << have one of these in every table

topic_title

topic_date

topic_content

 

and in the friends one::

 

friends_table << name

id

member_id << id of the person who made the friend request

friend_id << id of the person accepted the friend request

is_friend << if 0 friend request pending

 

all works nice as pic however i only want to show posts to those who are friends so if i go on my profile section i will see all my friends topics and they will see mine but i cant seem to fathem out the query i have tried many ways im confused i can get it to show mine no problem.

 

any suggestions? hope someone can help Thanks!!

Link to comment
https://forums.phpfreaks.com/topic/211549-php-bit-confused-with-a-query/
Share on other sites

Try

$id = 'member_id';  //members id you are searching for.
$sql = "SELECT a.*,b.* FROM member_topics as a, friends_table as b WHERE (a.member_id = b.member_id OR a.member_id = b.friend_id) AND ((b.member_id = '$id' OR b.friend_id = '$id') AND b.is_friend = 1)";

 

UN-TESTED.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.