leatherback wrote:well.. For starters..
Your database is asking for trouble..
Why do you have a colum for friend1, 2, and 3? Why not just have one table friends, with friend ID and person_id? That makes querying easier, to start with. And in the long run, you WILL decide you want to add other features, and you do not have to modify the basic sctructure of the database.
Come to think of it... Friend are people jut like the owen oer the page. So you could store the friends in the general persons database as well, add a colum "Registered", which is 1 (yes) or 0 (no) and you can easily add all their details, when the need arises. Just modify the forms, and off you go.
ANyway.. These are just ideas. Have a think about it.
Sorry, should've explained my table layout better.
TABLE friends
friend_id (pk, int)
friend1_userid
friend2_userid
friend_active
The friend1_userid is a foreign key for member_userid AND friend2_userid is also a foreign key for member_userid.
Say you have these three people
John Smith (member_userid = 1)
Tommy Jones (member_userid = 2)
Aaron Thomas (member_userid = 3)
If John Smith (1) goes to Aaron Thomas' profile page and clicks the link 'Add John Smith To My Friends List' it will insert the following into the friends table:
friend1_userid = 1
friend2_userid = 3
friend_active = 0
So, the person that requests the friend relationship is friend1_userid and the person the request is sent to friend2_userid. The next time Aaron Thomas logs in, I have a query that will count where friend2_user = 3 AND friend_active = 0. This'll tell Aaron Thomas he has 1 New Friend Confirmation Waiting. If he clicks 'Accept This Friend Request' it'll set friend_active = 1, if he denies it it will delete the row from the table.
Now, on the individual's profile pages I want to list all of his/her friends. So, their member_userid will not always be in friend1_userid, but could be in friend2_userid.
I'm trying to run a query to find WHERE friend1_userid = GET $userid OR friend2_userid = GET $userid
I can run that query and get what I want. That's why I have the IF statement in the body, the issue I am running into is matching up friend1_userid IF friend1_userid != GET userid OR matching friend2_userid IF friend1_userid != GET $userid, with the name info from the members table.