Jump to content

[SOLVED] adding friends


jakebur01

Recommended Posts

I've used a table structured like this:

 

CREATE TABLE `users_friends` (
  `ID` int(10) unsigned NOT NULL auto_increment,
  `UserID1` int(11) unsigned NOT NULL,
  `UserID2` int(11) unsigned NOT NULL,
  `Approved` enum('0','1') NOT NULL,
  PRIMARY KEY  (`ID`),
  UNIQUE KEY `UserID1` (`UserID1`,`UserID2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 

Let me know if this works for ya.

Link to comment
Share on other sites

Let's say 'tree' has the UserID of 1, 'apple' is 2, 'orange' is 3.

 

ID | UserID1 | UserID2      | Approved

1    1              2            1

2    1              3            1

 

 

Link to comment
Share on other sites

Yes, that is how it would work. This way you could do the 'pending requests' type thing.

 

And another table is because that's how it should be. You seem to know how it's working, give it a shot.

Link to comment
Share on other sites

I have basically the same table structure, but user_id and friend_id in place of UserID and UserID2 or whatever.  I use this query:

 

"SELECT u.* FROM friends AS f INNER JOIN users AS u ON f.friend_id = u.user_id WHERE f.user_id = '{$_SESSION['user_id']}' AND f.accepted='1'"

 

Play around with it to get it to work. =P

Link to comment
Share on other sites

DarkWater,

 

My entire conventions are different. The SQL standard is how you're doing it - lower cased with underscores. PHP is the same I do believe, but I like clean code with readability. ProperCased things look nice to me. :P

 

PS - What do you use '{$var}' over '".$var."' within queries? Just curious.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.