I made this mock-up for a project, and now I have to actually do it (in php) but I don't know how to get the data from the db so that I can create the html table.
Here is the definition of the tables involved:
grade:
grade_id | title | sort_order
-------------------------------
1 | Preschool | 10
2 | PreK | 20
3 | Kindergarten | 30
4 | Grade 1 | 40
5 | Grade 2 | 50
6 | Grade 3 | 60
competency_set:
competency_set_id | title | sort_order
--------------------------------------------------------
1 | Grouping and sequencing | 10
2 | Conecting: orientation | 20
3 | Conecting: reference | 30
competency:
competency_id | competency_set_id | grade_id | sort_order | title
--------------------------------------------------------------------------------------------------
1 | 1 | 1 | 10 | Procedure / Recount / Narrative Retell
2 | 1 | 2 | 10 | Procedure preK
3 | 1 | 3 | 10 | Procedure kindergarten
4 | 1 | 4 | 10 | Procedure Grade 1
5 | 1 | 5 | 10 | Procedure Grade 2
6 | 1 | 6 | 10 | Procedure Grade 3
7 | 1 | 2 | 20 | Recount / Narrative Retell PreK
8 | 1 | 3 | 20 | Recount / Narrative Retell Kindergarten
9 | 1 | 4 | 20 | Recount / Narrative Retell Grade 1
10 | 1 | 5 | 20 | Recount Grade 2
11 | 1 | 6 | 20 | Recount Grade 3
competency_set_id is a foreign key to competency_set.competency_set_id (PK).
grade_id is a foreign key to grade.grade_id (PK).
Ideally I'd like to have a result that allows me to loop in a very simple way, i.e.:
$rows = $this->getTableRows(); // the method that will return the mysql query result
foreach ($rows as $row) {
echo '<tr>';
echo '<td>' . $row->competencySetTitle . '</td>';
echo '<td>' . $row->preschool . '</td>';
echo '<td>' . $row->prek . '</td>';
echo '<td>' . $row->kindergarten . '</td>';
echo '<td>' . $row->grade1 . '</td>';
echo '<td>' . $row->grade2 . '</td>';
echo '<td>' . $row->grade3 . '</td>';
echo '</tr>';
}
Here is a screenshot of the mock-up with the different parts (competencies, competency sets and grades) explained:

gradetable (feel free to search for "pivot table join"). I would recommend a double loop in PHP instead.