Hi Rudy,
Here is the SHOW CREATE TABLE for members_contacts
CREATE TABLE `members_contacts` (
`member_id` int(10) unsigned NOT NULL default '0',
`contact_member_id` int(10) unsigned NOT NULL default '0',
`rel_a` tinyint(1) unsigned NOT NULL default '0',
`rel_b` tinyint(1) unsigned NOT NULL default '0',
`rel_c` tinyint(1) unsigned NOT NULL default '0',
`rel_d` tinyint(1) unsigned NOT NULL default '0',
`rel_e` tinyint(1) unsigned NOT NULL default '0',
`rel_f` tinyint(1) unsigned NOT NULL default '0',
`rel_g` tinyint(1) unsigned NOT NULL default '0',
`approved` tinyint(1) unsigned NOT NULL default '0',
`date_added` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`member_id`,`contact_member_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
The rel_ columns are just various flags to tell me more about the relationship between the two members.
Here is the members table but I’ve removed some of the general info columns
CREATE TABLE `members` (
`member_id` int(10) unsigned NOT NULL auto_increment,
`firstname` varchar(32) NOT NULL default '',
`lastname` varchar(32) NOT NULL default '',
`email` varchar(64) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
`is_active` tinyint(1) unsigned NOT NULL default '0',
`rpx_id` varchar(255) NOT NULL default '',
`rpx_twitter_id` int(11) NOT NULL,
`rpx_facebook_id` int(11) NOT NULL,
`is_suspended` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`member_id`),
KEY `rpxid_i` (`rpx_id`),
KEY `rpxtwitterid_i` (`rpx_twitter_id`),
KEY `rpxfacebookid_i` (`rpx_facebook_id`)
) ENGINE=MyISAM AUTO_INCREMENT=15504 DEFAULT CHARSET=latin1
Typically, I often display a list of members that belong to a certain ‘group’ and for each member displayed I need to show the connection status between that member and the logged in member. i.e. one of the following values will be shown against each member displayed: ‘connected’, ‘not connected’, ‘awaiting approval’.
In the interim I’ve resorted to getting a list of contact IDs with their approval status using a separate query like this:
SELECT
member_id,
contact_member_id,
approved
FROM
members_contacts
WHERE
member_id = $memberid
OR
contact_member_id = $memberid
… and then I using PHP code to create an array of contact IDs with approval status. Then for each member displayed I check if that member’s ID is withn the array of contacts and display the relevant connection status. That method currently works quicker than doing it all in 1 query.
I hope that makes sense.
Many thanks 