douya7282 2017-08-13 17:37
浏览 4
已采纳

从数据库中检查3表,同时保存每个表的信息以进行身份​​验证登录表单php [关闭]

I have tables like this

Employee

Id | IdEmployee  | Employee | Address     | Phone_num | 
1  | EM10000     |  Jack    | wall st.    | 9000010   | 
2  | EM10001     |  Paul    | elm st.     | 9000010   |
3  | EM10002     |  George  | ex  st .    | 9000010   |

Technician

id | IdTech      | TechName | Address      | phone_num | 
1  | TE10000     | Gabut    | Hello st.    | 9000010   | 
2  | TE10001     | Polnaref | coding st.   | 9000010   |
3  | TE10002     | Rafioli  | stack st.    | 9000010   |

Admin

id | IdAdmin     | username | password     | phone_num | 
1  | AM10000     |  sim1    | 1234         | 9000010   | 
2  | AM10001     |  sim2    | luvcoding    | 9000010   |
3  | AM10002     |  sim3    | okaymate     | 9000010   |

How do i make Table Technician and Employee become a user too, so they could use their information as username in a login form? Plus, i want each Id (not the "AutoIncrement" ID) of Technician and Employee would become the username.

How to manage the database like this?

or should i add password column in both tables? (Employee and Technician)

or should i make one table just like this?

(new) Admin

id | Id          | username | password     | phone_num | 
1  | AM10000     |  sim1    | 1234         | 9000010   | 
2  | AM10001     |  sim2    | luvcoding    | 9000010   |
3  | AM10002     |  sim3    | okaymate     | 9000010   |
4  | AM10003     |  EM10000 | test1        |  NULL     |
5  | AM10004     |  EM10001 | test2        |  NULL     |
6  | AM10005     | EM10002  | test3        |  NULL     |
7  | AM10006     | TE10000  | 1234         |  NULL     | 
8  | AM10007     | TE10001  | ok123        |  NULL     |

There is no relationship between Technician and Employee (stand-alone table)

  • 写回答

1条回答 默认 最新

  • doubang9906 2017-08-13 18:04
    关注

    In your case, you would be better making your tables in normalization form as follows:

    Employees

    IdEmployee  | Employee | Address     | Phone_num 
    EM10000     |  Jack    | wall st.    | 9000010  
    EM10001     |  Paul    | elm st.     | 9000010  
    EM10002     |  George  | ex  st .    | 9000010 
    

    Technicians

    IdEmployee | TechName 
    TE10000    | Gabut   
    TE10001    | Polnaref
    

    Admins

    IdEmployee  |  Password  
    TE10001     |  hashed_pass1 
    EM10002     |  hashed_pass2 
    

    This makes sure you have no replicated data and ensures you can associate tables correctly by using foreign keys.

    So if your admin has IdAdmin 'EM10002', to get the password of that employee with the following query:

    // Will return a row with EM10002's password, which is 'hashed_pass2'. 
    SELECT Password from Admins WHERE IdEmployee = EM10002
    

    Here is another example of foreign key usage.

    To understand normalization more, have a look at this thread.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历