I'm trying to develop a student attendance form using Codeigniter & MySQL. My table structure for the two tables are as follows:
student_mst table
-----------------
s_id(pk)
s_name
s_acssn_id
s_prog_id
s_admission_no
s_photo_name
stu_attendance table
--------------------
sa_id(pk)
sa_s_id(fk)
sa_s_acssn_id
sa_s_prog_id
sa_atten_dt
sa_atten_code(A=Absent,P=Present)
sa_teacher_id
The design of my interface is as shown in the image below:
My plan is, on any particular date, a teacher can mark a student as either Present or Absent from the Action buttons for which ajax code is there which inserts rows in the above-mentioned stu_attendance table. And also every new day when the attendance entry form is opened, the Datatable plugin should open just like as shown in the image.
In order to accomplish my plans, I'm populating a Datatable plugin using the following query:
SELECT a.s_id AS sid,a.s_prog_id AS progid,a.s_acssn_id AS ssnid,a.s_name AS sname,a.s_admission_no AS sadmsnno,a.s_photo_name AS sphotonm,
b.sa_atten_code AS acode
FROM student_mst a
LEFT JOIN stu_attendance b
ON a.s_id = b.sa_s_id
The above SQL query works well for the first time (i.e. when stu_attendance table is empty) and populates the Datatable plugin as shown in the above image. I'm able to mark students as Present/Absent.
However, my plan fails the next day, because as per the query written above, it also picks and shows records of the students from the previous day which is not desired.
I hope I have made my problems clear. Anyone, please guide me. Should I change my table structures or should I change my design interface or should change my SQL query. Please help maybe with some code/examples.