简体   繁体   中英

Assigning a user to multiple projects in my PHP application, best approach?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM