I have a MySQL database named "Problems":
year type model
---- ---- -----
2016 Cars A
2016 Cars B
2015 Cars A
2014 Cars C
2015 Vans D
2014 Vans E
For different "types" of vehicles, it lists the "model" that has a problem and the year(s) in which these models have problems.
I need to create a separate HTML table for each type of vehicle. In each table, I need a row for each model and a column for each year. I will use "Y" in a cell to designate a problem, and a period (".") to designate no problem.
That is, I need to create the following two HTML tables:
HTML table for Cars:
2016 2015 2014
A Y Y .
B Y . .
C . . Y
HTML table for Vans:
2016 2015 2014
D . Y .
E . . Y
I will be using mysqli in PHP to query the database and construct the tables. I suppose I could make a separate query for each table, but that doesn't seem like the most economical approach. Can a query be executed that will return ordered rows so that I can basically do an iteration pattern like this?
for type in types:
// write start of <TABLE>
for model in models:
// write start of <TR>
for year in years:
// write <TD>
// write close of <TR>
//write close of <TABLE>
If it would make more sense to execute many different queries, please advise.