Adam Posted February 1, 2012 Share Posted February 1, 2012 You'll need to modify the user table column names, as I had to guess what they're called. Quote Link to comment https://forums.phpfreaks.com/topic/256122-getting-php-to-work-with-relationship-tables/page/2/#findComment-1313391 Share on other sites More sharing options...
DonaldFaulknor Posted February 1, 2012 Author Share Posted February 1, 2012 is it users table or friends table? The friends are listed in a friends table, wasn't aware I should use the users table at all. select s.statuses, s.whens, u.id, u.name from Statuses s join Users u on (s.users_id = u.id) join Friends f on (u.id = f.friend.id) where f.users_id = 123 order by s.whens; There's some things I don't understand about this. s and u, is that suppose to be the name of the table? Statuses.statuses and Users.id also... FROM? Statuses s - is the lowercase s the name of the column statuses inside the table Statuses? Are the (parenthesis) part of the statement or just a note? Quote Link to comment https://forums.phpfreaks.com/topic/256122-getting-php-to-work-with-relationship-tables/page/2/#findComment-1313393 Share on other sites More sharing options...
Adam Posted February 1, 2012 Share Posted February 1, 2012 As pointed out before, storing user information within a friend relationship table is a bad idea. You said there was a separate table for the user data - I guessed a couple of the column names in my SQL. What's the point in showing the status if you can't say anything about who posted it? Joining the user data would be something you would need to do at some point. s, u and f are just aliases: [...] from Statuses s join Users u on (s.users_id = u.id) join Friends f on (u.id = f.friend.id) [...] You could also declare them with an optional "as" if you find it easier: [...] from Statuses as s [...] The parentheses are also optional - personally I just prefer them. Quote Link to comment https://forums.phpfreaks.com/topic/256122-getting-php-to-work-with-relationship-tables/page/2/#findComment-1313395 Share on other sites More sharing options...
AyKay47 Posted February 1, 2012 Share Posted February 1, 2012 collectively, I'm going to say that you should be studying more about Mysql and PHP before attempting to make the next Facebook like 100000000 other programmers. Study hard, learn, and then come back and attempt to make this kind of website the correct way. Quote Link to comment https://forums.phpfreaks.com/topic/256122-getting-php-to-work-with-relationship-tables/page/2/#findComment-1313397 Share on other sites More sharing options...
KevinM1 Posted February 1, 2012 Share Posted February 1, 2012 You need to think hard about your db design and normalize your tables. Here's a primer: http://mikehillyer.com/articles/an-introduction-to-database-normalization/ Quote Link to comment https://forums.phpfreaks.com/topic/256122-getting-php-to-work-with-relationship-tables/page/2/#findComment-1313400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.