Momoh Bamidele
Momoh Bamidele

Reputation: 21

Complex Query for Displaying comments based on friends added

I have a very big problem with my website. I have a form, more like a text box used in submitting comments, that not the problem. The problem is displaying the comments. I want to display comments based on the friends a user added like the way facebook, twitter does.

I have 3 tables:photo_tb, comment_tb, friendship_tb.

The friendship_tb contains columns name, friend. name stores your email and friend stores the email of the person you add....

I need the photo_tb to get the picture of the person making the comment and I use a mysql join successfully.

In my comment_tb...i get the email of the person making the comment in my commentname column and comment made by the person...

I want to to show comment by ffriendship like if Mr A adds Mr B and Mr c..when Mr A logs on he should only get comments by both Mr B and Mr c and his comments doe not comments from Mr G or H.

This is what i have so far

SELECT
     comment_tb.comment_id
   , comment_tb.comname
   , comment_tb.comment
   , comment_tb.time
   , photo_tb.name
   , photo_tb.photo
   , friendship.name
   , friendship.member
FROM comment_tb, photo_tb, friendship
WHERE
        comment_tb.comname=photo_tb.name
    and friendship.name = colname

The colname is a variable for MM_Username ,the session variable when you log in is meant to display comments related to you.

The sql statement attaches the picture to each comment name successfully but doesn't limit the comment to friends added.

Upvotes: 1

Views: 111

Answers (1)

Barmar
Barmar

Reputation: 781721

Add and friendship.member = comment_tb.comname.

BTW, it would be nice if the column names in your SQL matches what you said in the description. I'm just guessing that friendship.member is what you called friend in the text.

Upvotes: 1

Related Questions