wwfc_barmy_army Posted June 6, 2008 Share Posted June 6, 2008 Hello. Right, i'm not sure how i'm going design this database and i'm looking for some advice. Basically what it needs to store are users (userid) and their contact details, eg msn, icq, aim, yahoo etc, but each one can be active or inactive for each user. Although i could just have set fields for each contact method but i want to be able to add/delete contact methods. Any suggestions/Ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 6, 2008 Share Posted June 6, 2008 If you don't want them in the users table, then you can add another table called contact_information, or something like that, with the following fields: contact_id (primary key; auto increment), user_id (references the id in the users table; has index), type, data. Then to get a users contact information you could do: SELECT type, data FROM contact_information WHERE user_id = 1234; Quote Link to comment Share on other sites More sharing options...
keeB Posted June 8, 2008 Share Posted June 8, 2008 If it were a (big) project where the type of client really matters, I'd do something like this. Pseudo Database code: create table Person ( userId int, firstname text, . . . ) create table contact_base ( id int, userId int references person(userid), //foreign key to person.userid enabled boolean ) create table msn ( id int references contact_base(id) // foreign key on contact_base.id -- properties , -- unique , -- to , -- msn , } Representation in PHP: <?php class Person { $private $userid = null; . . } class Contact_Base { private $enabled = false; private $id = null; . . . } class MSN extends Contact_Base { # unique msn properties } class PersonDao { function fetchContactInfo($userId) { $q = "SELECT * FROM Contact_Base cb INNER JOIN MSN m on msn.id = Contact_Base.id -- INNER JOIN AIM (etc) where cb.userId = $userId"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.