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.

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.