简体   繁体   English

用户登录后在数据库上的网页上显示合适的信息

[英]Display suitable information on web page from database after user logs in

I have some PHP codes and a database. 我有一些PHP代码和一个数据库。

  1. User can register using roll number, password and semester. 用户可以使用卷号,密码和学期进行注册。 I do plan to provide department as well later. 我确实打算稍后再提供部门。
  2. Teacher can add subjects based on semester. 教师可以根据学期添加科目。 They can add class tests based on subjects. 他们可以根据科目添加课堂测试。
  3. In my simplest case, I have been able to login and see all subjects and all tests on pages ' view_subjects.php ' and ' view_tests.php ' respectively using SELECT * .. 在最简单的情况下,我可以使用SELECT * ..分别登录并查看页面“ view_subjects.php ”和“ view_tests.php ”上的所有主题和所有测试SELECT * ..
  4. I want to include a simple modification. 我想包含一个简单的修改。 I want to be able to show subjects and tests based on semester user is in, ie filter. 我希望能够显示基于学期用户所在的科目和测验,即过滤器。
  5. I have created views I, II, III, IV where view names are semesters and are based on CREATE VIEW II AS SELECT * subjects WHERE semester='II'; 我已经创建了视图I,II,III,IV,其中视图名称是一个学期,并且基于CREATE VIEW II AS SELECT * subjects WHERE semester='II'; And Views I, III, IV respectively. 和意见一,三,四。 Edit- Realised that it is not necessary. 编辑-意识到没有必要。
  6. Based on views, I want to execute SELECT * FROM [viewname] on step 3. Eg: SELECT * FROM [I] , SELECT * FROM [II], ... SELECT * FROM [IV] 基于视图,我想在步骤3上执行SELECT * FROM [viewname] 。例如: SELECT * FROM [I] , SELECT * FROM [II], ... SELECT * FROM [IV]
  7. But the suitable statement out of the four has to be executed based on the user logging in. 但是必须根据用户登录来执行这四个语句中的适当语句。

Is my approach correct? 我的方法正确吗?

If so, how can I get the semester name after if he/she logs in Otherwise, how should I approach this problem? 如果是这样,他/她登录后如何获得学期名称?否则,我该如何解决这个问题?

Edit My problem is to add a filter. 编辑我的问题是添加一个过滤器。 I want users to see their subjects and tests based on the semesters they are in. Semester is an attribute of the student table along with roll_no and password. 我希望用户根据他们所在的学期查看他们的主题和考试。学期是Student表的属性以及roll_no和password。

I hope this makes sense, Im not going to write code as i dont know what you are working with there, but for situation like this, Following will be the basic idea. 我希望这是有道理的,我不会编写代码,因为我不知道您在那里使用的是什么,但是对于这种情况,以下将是基本的想法。

Method one(i do not prefer this) 方法一(我不喜欢这样)

  1. Add a current_semester field in student table, where you store semester id. 在学生表中添加current_semester字段,用于存储学期ID。 This is to be updated every time a student completes a semester. 每当学生完成一个学期时,此信息都会更新。

  2. before loading your information page, save the value of current_semester in a variable, and use something like, "SELECT * FROM [semester table] WHERE id = [current_semester]" 在加载信息页面之前,将current_semester的值保存在变量中,并使用类似“ SELECT * FROM [semester table] WHERE id = [current_semester]”的名称

This will give you the current semester of his/her semester where ever you want but it will not save his semester history. 这将为您提供他/她本学期的当前学期,无论您要去哪里,但都不会保存他的学期历史。

Advised Method(using different table to save student's semester history) 建议的方法(使用不同的表格保存学生的学期历史)

  1. create new table "student_semester" with id, semester_id(foreign key from associated semester), student_id(foreign key from associated student), start_date and any other info that you may want. 使用ID,semester_id(关联的学期的外键),student_id(关联的学生的外键),start_date和您可能需要的其他任何信息创建新表“ student_semester”。
  2. simply get the latest record associated with that user which will be the current semester 只需获取与该用户相关联的最新记录,这将是当前学期
  3. this method will allow you to store semester history each student 这种方法将允许您存储每个学生的学期历史

Advise: Use Laravel, Eloquent makes this sort of work extremely easier. 忠告:使用Laravel,Eloquent使这种工作非常容易。

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

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