dqdmvg7332 2013-10-24 20:15
浏览 265
已采纳

3种不同用户类型的数据库设计指南

I am creating my first web application with mySQL & PHP and just looking for some guidance to ensure I'm on the right lines... or not.

It will have 3 types of user; members, clubs and admins.

I currently have them all logging in through the same log in page and once logged in they go to the same 'dashboard' but the content of the dashboard is changed via conditional statements against the users user type. Is this a sensible idea in terms of security etc?

My current simplified table structure is:

users   {id, username, hashed_password}
members {id, user_id, first_name, last_name, email, address, tel, cleared_activities}
clubs   {id, user_id, club_name, address, tel, available_activities}
admins  {id, user_id, first_name, last_name, email, address, tel}

Could this table design be improved upon? I'm conscious of the similar fields, especially amongst members and admins and this makes me think there is likely a better way.

Many Thanks

  • 写回答

1条回答 默认 最新

  • dougaoxian8922 2013-10-24 20:28
    关注

    Since all members and admins are users, I would use one table for user, members and admins adding one extra field "usertype".

    Then I would add a table only for members, that would hold all extra fields that are member specific.

    users       {id, username, hashed_password, first_name, last_name, email, address, tel, user_type}
    member_data {user_id, cleared_activities}
    clubs       {id, user_id, club_name, address, tel, available_activities}
    

    If the extra member fields are just the one you mention, you could also keep it in the users table. For the users that are not of type member, this field will have NULL values.

    users       {id, username, hashed_password, first_name, last_name, email, address, tel, user_type, cleared_activities}
    clubs       {id, user_id, club_name, address, tel, available_activities}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!