简体   繁体   English

如何处理不同类型的用户?

[英]How to handle different types of users?

my site is now going to start allowing two different types of users to sign up... 我的网站现在开始允许两种不同类型的用户注册...

  1. normal people 普通人
  2. companies 公司

the two will be able to do all the same things on the site, but their profiles will look different, and im sure they will want to store different types of information about themselves. 这两个人将能够在网站上做同样的事情,但他们的个人资料看起来会有所不同,我相信他们会想要存储不同类型的自己的信息。

my question is: should i store them on separate mysql tables? 我的问题是:我应该将它们存储在单独的mysql表中吗? or...should i put them on 1 and label them as "user" or "company"? 或者......我应该把它们放在1上并将它们标记为“用户”或“公司”吗?

I could really use your input to help me to avoid pitfalls with either... 我真的可以用你的输入来帮助我避免陷阱...

thanks! 谢谢!

This link explains some best database practices. 此链接解释了一些最佳数据库实践。

I'd create an "Accounts" table with a UID, with common information between the two stored there, and which type of account it is. 我创建了一个带有UID的“帐户”表,其中存储了两者之间的公共信息,以及它的帐户类型。

Then a "Companies" table with company specific information, using the same UID as the account, and, I dunno, a "Users" table with information specific to users. 然后是“公司”表,其中包含公司特定信息,使用与帐户相同的UID,并且我不知道,“用户”表包含特定于用户的信息。

This prevents you from having to make two very similar tables, having unused columns, or duplicating data. 这可以防止您必须创建两个非常相似的表,使用未使用的列或复制数据。

Like this: 像这样:

Accounts
UID|UserName|Password|Account Type

Companies
UID|Company Name|Address|Contact Person

Users
UID|First Name|Last Name|Display Name

Don't put them in completely seperate tables or else you have to look up usernames, account details in 2 different places giving you if statements everywhere. 不要将它们放在完全独立的表中,否则你必须在两个不同的地方查找用户名,帐户详细信息,以便在任何地方提供语句。 Then you'll have a bitch of a time trying to do referential integrity and trying to make the "orders" table refer to a user OR a customer table. 然后你会有一个时间的婊子试图做参照完整性并试图使“订单”表引用用户或客户表。 Either put shared info into one table and put specific stuff in extra tables or put everything in one big table. 将共享信息放入一个表中,并将特定内容放在额外的表中,或者将所有内容放在一个大表中。

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

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