简体   繁体   English

将用户分配给我的PHP应用程序中的多个项目,最好的方法是?

[英]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. 我目前正在为我的工作构建一个Web应用程序,您可以添加任务,项目和客户端。 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). 该应用程序是基于最新版本的Codeigniter 2.0构建的(如果有帮助)。 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. 我想出的一种解决方案是将客户端的项目ID列表存储在名为“ belongs_to”的表字段中,并以逗号分隔。 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: 为什么不只有3个桌子:

  1. Table projects : id, name, etc etc 项目 :ID,名称等
  2. Table clients : id, name, etc etc 客户端 :ID,名称等
  3. Table clients2projects : id, id_project, id_client client2projects :id,id_project,id_client

In this way the third table maps projects and clients in a many to many relationship 通过这种方式,第三张表以多对多关系映射了项目和客户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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