• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
filter using mysql query.. simple social network website

Hi. Im currently building a simple social network. But I'm a little bit stuck. Here's the problem:

I made a latest wall posts widget that shows the latest posts of the poeple he/she is following. It is working fine. But the problem is it is also showing the followed users wall posts in other users profile. I want to filter the posts, only the post that is posted in the profile of the poster will be shown. Sorry for my bad english I hope someone will understand what I'm talking about.

Here is my current code to query the posts:
function get_stalked_users_latest_posts($usernames, $limit, $order = 'desc')
$this->db->select('post, author');
$this->db->where_in('author', $usernames);
$this->db->order_by("date_time", $order);
$query = $this->db->get('posts');

return $query;

explanation for the mysql query -- I currently have a where_in statement for fetching the posts because $usernames is an array. $usernames array is the usernames of the persons that the current logged in user has followed/stalked. It works, the only problem is how can I filter it so it will only show the posts of the user if the post has been posted in his/her own profile. hmmm.

Thanks in advance for your responses Smile

[quote author="rei" date="1344062985"]how can I filter it so it will only show the posts of the user if the post has been posted in his/her own profile.[/quote]

Just to make sure I understand what you are looking for:

1. User A is following (stalking) User B
2. User B posts a post on their profile (Post 1)
3. User B posts a post somewhere else (Post 2)
4. You want Post 1 to show up in User A's wall, but you don't want Post 2 to show up.

How do you determine where the posts were posted? Is it something you are currently tracking?

Hi sir thanks for your response. I can determine where the posts were posted because in the posts table I have a column for username(the owner of the profile) and the author(the poster).. Nwei I solved the problem by just adding another column named -- post_to_self (1 for TRUE and 0 for FALSE). So I can just filter it by adding WHERE post_to_self = 1 in the sql query. Nwei thanks sir for your response Smile

couldn't you just add another where clause
where username=author

If username is the owner of the profile that the post is on, and author is the one who posted the post,
doesn't that mean that if username and author are the same, it is a post_to_self?

yes I could do that if I'm only stalking 1 person. But the problem is I'm stalking many different persons so I cannot do it like that. Take note that the $usernames variable contains the people I had stalked or followed. It is a 1 to many relationship.

And remember that I'm using a where_in clause because it contains an array. it is not just a simple where clause.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.