Jump to content

Suggestion for Database Design


Recommended Posts

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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";
    }
}
?>

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.