Note that there are some explanatory texts on larger screens.

plurals
  1. POquery structure
    primarykey
    data
    text
    <p>So, I'm currently doing a small attendance system.</p> <p>I have a problem structuring the necessary code to work with what I need.</p> <p>So, to make things short, I have a page named TAKE ATTENDANCE in which the user selects the course, time start, time end and group.</p> <p>I have the following tables:</p> <pre><code>CREATE TABLE period ( periodID INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, periodStart DATE NOT NULL, -- The start date for the period periodEnd DATE NOT NULL, -- The end date for the period period_Att DATETIME, -- When the attendance should be delivered - irrelevant for now ) Engine=InnoDB; CREATE TABLE attendance ( attID INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, att_courseID INT UNSIGNED NOT NULL, att_periodID INT UNSIGNED NOT NULL, lesson_start TIME NOT NULL, lesson_end TIME NOT NULL, att_duration TIME, --duration in time att_userID INT UNSIGNED NOT NULL, att_taken TINYINT(1) NOT NULL DEFAULT 0, FOREIGN KEY att_courseID REFERENCES course (courseID), FOREIGN KEY att_periodID REFERENCES period (periodID), ) Engine=InnoDB; CREATE TABLE student_attendance ( studentID INT UNSIGNED NOT NULL, attendanceID INT UNSIGNED NOT NULL, FOREIGN KEY studentID REFERENCES students (studentID), FOREIGN KEY attendanceID REFERENCES attendance (attendanceID), ) Engine=InnoDB; </code></pre> <p>What I want is that in the VIEW ATTENDANCE section, the user selects the course and period, and the attendance taken is displayed in the following format:</p> <pre><code>Week 1 - (30 hours of school hours per week) 1/1/2012 --- Joe Borg 4 hours (sum of hours is needed here) --- Nancy Ping 5 hours --- John Quin 5 hours 2/1/2012 3/1/2012 4/1/2012 5/1/2012 6/1/2012 7/1/2012 </code></pre> <p>or else to make things easier, I can remove the dates</p> <pre><code>Joe Borg 28 hours Nancy Ping 30 hours John Quin 27 hours Week 2 etc Week 3 etc Week 4 etc </code></pre> <p>Any idea how the SQL would be done? I tried the following though this gets all the data and is a bit confusing:</p> <pre><code>SELECT * FROM periods,attendance,student_attendance,students,course,stipend,users WHERE attendance.att_periodID = periods.periodID AND attendance.att_courseID = course.course_ID AND attendance.att_userID = users.userid AND student_attendance.attendanceID = attendance.attID AND student_attendance.studentID = students.stud_ID AND students.stud_StipendID = stipendID AND attendance.att_courseID = '$course'; AND attendance.att_periodID = '$period'; </code></pre> <p>I also retrieved the course hours according to the course selected by using:</p> <pre><code>SELECT course_Hours FROM course WHERE course_ID = '$course'; </code></pre> <p>What SQL do I need to get such data structure? I'm a bit confused.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload