I have an Attendance system in one of my module project using PHP and MySQL, the MySQL table looks something like this:
Now, timetable is used to store the Time Table for classes in a day for a section and which teacher is assigned to it. The student_info table contains general information about students and the section they belong to. The attendancetable is used to record those who are absent using time and student id as primary key.
I could get a count of how many classes were taken in a semester as follows:
SELECT count(*) as total FROM timetable WHERE flag > ? AND semester = ? AND section = ? AND timeid BETWEEN ? AND ?
Then computed how many times a student attended and also calculate the percentage of attendance.
SELECT stu.* ,
(SELECT COUNT(*)
FROM attendancetable att
WHERE att.s_id = stu.class_roll
AND att.semester = ?
AND att.timeid BETWEEN ? AND ? ) AS absent
FROM student_info stu
WHERE stu.section = ?
AND stu.logYear = ?
AND stu.deleted = ?
ORDER BY stu.class_roll
Now, I want to also display a kind of attendance sheet as follows:
I tried SQL Inner Join but didn't get the way I wanted.
I was thinking that the first row can be output form the following query:
SELECT timeid
FROM timetable
WHERE flag > ?
AND semester = ?
AND section = ?
AND timeid BETWEEN ? AND ?
[UPDATE] Found a way to do this, given as an answer, don't know if that's the right way.
Thank You in advance for helping.


