Display Friends |
[eluser]mStreet[/eluser]
Hello! I'm currently just fooling around with Codeigniter, but I'm stuck trying to build a friendship system. My Friendships database looks like this: User_id, Friend_id, Status If Friend_id or User_id is the logged in person then fetch the one that isn't the logged in ID and output say username instead of friend_id in the view. I've tried a lot of different methods but just can't seem to get it working. Please help me out, thanks!
[eluser]aquary[/eluser]
What have you tried? we need some base to start. There is also something about how you store relationship. Do you store 1 relation (X <-> Y = X and Y are friends) or 2 (X -> Y, Y -> X = X is a friend of Y, and Y is a friend of X)?
[eluser]mStreet[/eluser]
This is what my model looks like. Code: function friends() I'm sorry, I don't understand your question with the x's and y's. Could you please clarify it for me?
[eluser]aquary[/eluser]
How you store data when X is a friend of Y. User_id, Friend_id, Status // either this X_id, Y_id, 1 // or these, two way relationship X_id, Y_id, 1 Y_id, X_id, 1 The second case is easier to lookup for relationships since it'll be just "Looking for those who are my friend (User_id is my id)" while the first case is easier for maintenance, but hard on "looking for those whois my friend, and I'm their friend (User_id is my id OR Friend_id is my id)". From the code, you are seems to be the first one. * El Forum on thinking mode.
[eluser]aquary[/eluser]
Just to make it easier to read >_> Code: function friends() ... Actually, I didn't even know yet what is your current result >_>? edit: change the where condition
[eluser]mStreet[/eluser]
Yes, I want to do it like the first one you mentioned. The second one just seems a bit too much. It has to be possible! Although, I have no clue how to do it. Thanks!
[eluser]mStreet[/eluser]
After trying your code I got an error: Code: A Database Error Occurred
[eluser]aquary[/eluser]
Did you forget something? normally the query should be.. Code: // The last backtick should be inside. And the full one would be... Code: // replace all number by your real data
[eluser]mStreet[/eluser]
The error is gone. This is what it shows me: http://localhost/codeigniter/friends - Logged in as John My friends: Mitchell = Correct http://localhost/codeigniter/friends - Logged in as Mitchell My friends: Mitchell
[eluser]aquary[/eluser]
check the queries of both cases, what are the different between them ? |
Welcome Guest, Not a member yet? Register Sign In |