views:

46

answers:

1

I am currently building a web application for my work and you can add tasks, projects and clients. The dilemma I've encountered is that a client can be assigned to multiple projects at once.

The application is being built upon the latest version of Codeigniter 2.0 (if that helps). I am usually pretty good at working out problems like this, but I can't get my head around this one.

One solution I came up with is to store a list of project ID's for the client in a table field called 'belongs_to' and separate them by comma. Sure this method would work, but it just seems a little messy and I am sure that there is another way, my mind just can't come up with the solution.

Your help is gratefully appreciated.

+5  A: 

Why not just have 3 tables:

  1. Table projects: id, name, etc etc
  2. Table clients: id, name, etc etc
  3. Table clients2projects: id, id_project, id_client

In this way the third table maps projects and clients in a many to many relationship

nico
Fantastic. I can't believe I never thought of that, such an easy and elegant solution to implement and use. Thank you for answering so fast and precisely.
Dwayne
@Dwayne: glad it helped!
nico
I'm implementing something very similar to this scenario and this even aided me in my software I'm writing. Thanks nico!
jlafay