Jump to content

Recommended Posts

SELECT * FROM post WHERE post_id NOT IN (SELECT post_id FROM ignore)

though if user_id in the ignore table is the user who ignored the post, you would have something like this... assuming the user id is stored in the session

SELECT * FROM post WHERE post_id NOT IN (SELECT post_id FROM ignore WHERE user_id='{$_SESSION['user_id']}')

Hi.

 

It doesn't seem to be working.

 

My code is a little more complicated, I'm not sure I'm implementing it correctly.

I've created a friends system, whenever a friend creates a post it will be displayed to his/her friends.

This is the query that displays it to them. I want to filter out any posts that are ignored.

 

SELECT Users.id, Posts.post, Users.username, Posts.post_id
FROM Posts, Users, Friends
WHERE Posts.username_id = Users.id 
AND Friends.user_id = $user 
AND Friends.friend_id = Posts.username_id
NOT IN (SELECT Posts.post_id FROM ignore)

you have to select post_id from ignore, not posts.post_id, as they are seperate queries...

SELECT Users.id, Posts.post, Users.username, Posts.post_id
FROM Posts, Users, Friends
WHERE Posts.username_id = Users.id 
AND Friends.user_id = $user 
AND Friends.friend_id = Posts.username_id
NOT IN (SELECT post_id FROM ignore)

 

.. though that will return the post_id of every ignored post, by any user. you need to change the last select to incorporate the user's id, i.e.

SELECT Users.id, Posts.post, Users.username, Posts.post_id
FROM Posts, Users, Friends
WHERE Posts.username_id = Users.id 
AND Friends.user_id = $user 
AND Friends.friend_id = Posts.username_id
NOT IN (SELECT post_id FROM ignore WHERE user_id=$user)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.