Link to home
Start Free TrialLog in
Avatar of sahanz
sahanz

asked on

Show updates from a table, (facebook wall) - php

This for something like facebook wall, our updates and friends updates. Right now I have a table to keep updates and another table  to keep friends information for a specific user(user_id and his/her 's friends ids). There is a user table and a page for each user; when someone visit the page, we check for the users friends and show updates from the update table of the user and users friends. What should I do to get something like this?. I dont want the coding, just a method or a way to do it.

Thanks


P.S:- Using php and mysql
Avatar of birwin
birwin
Flag of Canada image

We probably need more information. I assume you are using PHP/mySQL, since you posted in this section.
How are you storing the friends relationship? What data is held in the "Friend's Information table?
What are you trying to update.
How is that update stored on the "Updates Table"? Is there a line per change with a datestamp and username? How are the changes noted? Is the Update Table" data ever moved to the User Table?
Brian
Avatar of sahanz
sahanz

ASKER

Hi,

Let me explain in other way, I have a user_table which contains users information such as username email address etc, and each of the user has an ID, Another table contains relationship between the users of the table, lets say the table is "friends", in front end these relations are working like this, users can become friends, so we're keeping the relationships between friends in "friends" table. Another table called "updates" has status updates(like in twitter) for each user, so the updates table has a ID for each update, text column for the update text, and user_id column coz we need to know who did this update.


For the users in "user_table" we have a profile page, we list the users details and his/her updates. Along with users updates we need to list his/her friends updates, lets say users who has the ID 1  and 2 are friends, and both of these users have status updates in "updates" table. Lets say someone visit the profile page which is for user ID-2 we grab the updates from "UPDATES" according to the user's id and show them in the page, but like I said I need to show the updates of this user, in this case updates of user ID - 2. But how to do that?
ASKER CERTIFIED SOLUTION
Avatar of Snarfles
Snarfles
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might be able to use Snarfles suggestion in a single query.  Something like this...

SELECT * FROM updates WHERE user_id IN (SELECT friend_id_2 FROM friends WHERE friend_id_1 = '123');
It would need the current users id in the list as well Ray, so assuming your select works then it would need to be something like

SELECT * FROM updates WHERE user_id IN (SELECT DISTINCT friend_id_2 FROM friends WHERE friend_id_1 = '123' AND friend_id_2 = $user_id);

So adding to the query is an additional condition "AND friend_id_2 = $user_id" to get the current user's id in the query and then also "DISTINCT" will tell it to only return unique rows so that you dont get 100 versions of the current user_id in the list.
Yeah, good point.  I tend to test these things one-line-at-a-time when it's my own work.  DISTINCT and GROUP BY or something like that usually percolates up.  But I'm not sure whether it would matter if you had multiples in the second-tier select.  I'm sure it would not hurt to have a distinct list, but wouldn't the non-distinct query look somewhat like this:

SELECT x FROM updates WHERE user_id IN (101,101,101,123,123,456)

I've never observed the behavior, but MySQL might be smart enough to do something like array_unique() with that list.  Would be an interesting thing to test.
Avatar of sahanz

ASKER

Hi, First one works well, and second one works well without the current users id, as soon as I put "AND" and user it it returns empty results.
Avatar of sahanz

ASKER

Hi, First one works well, and second one works well without the current users id, as soon as I put "AND" and user it it returns empty results.