简体   繁体   中英

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

I have some PHP codes and a database.

  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 * ..
  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'; 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]
  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.

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. 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]"

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.
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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