Sorting, grouping multiple times
I have to admit I have no idea where to start with this one. I have a bunch of lesson plans in a database, they have various fields like this:
unitOrLesson
title
grade
subject
inProgess
I need to display them all on a page sorted in a few different ways. One way would be by grade, then subject, then lesson or units, then in progress or completed. So it would be:
GRADE LEVEL
SUBJECT - Lesson plans
Title of in progress lesson 1
Title of in progress lesson 2
Title of in completed lesson 1
Title of in completed lesson 2
SUBJECT - Unit plans
Title of in progress Unit 1
Title of in progress Unit 2
Title of in completed Unit 1
Title of in completed Unit 2
Another option would be by subject, then grade, then lesson or units, then in progress or completed. Like this:
SUBJECT
GRADE - Lesson plans
Title of in progress lesson 1
Title of in progress lesson 2
Title of in completed lesson 1
Title of in completed lesson 2
GRADE - Unit plans
Title of in progress Unit 1
Title of in progress Unit 2
Title of in completed Unit 1
Title of in completed Unit 2
I started writing a the query below, and then realized I had absolutely no idea where to go or how to make this happen:
SELECT kits.kitsID,
kits.unitLesson,
kits.status,
kits.title,
grade.level,
subjects.subjectName,
grade.gradeID
FROM kits INNER JOIN grade ON kits.grade = grade.gradeID
INNER JOIN subjects ON kits.subject1ID = subjects.subjectsID
ORDER BY grade.gradeID ASC, subjects.subjectName ASC
Of course the above doesn't work. I just don't know how best to get this out of the database and onto the page. Any help would be greatly appreciated.
