The amount of columns in a table is based upon the amount of data in a table. The amount of rows in a table is based on the amount of rows in a different table. An example of these tables are below
environments patches
id | name id | name
____|______ ____|____________
1 | dev 1 | firstPatch
2 | test 2 | secondPatch
3 | prod 3 | thirdPatch
The end result of what I'm looking for would be the following <table>
_________________________________
| Patch Name | dev | test | prod |
|_____________|_____|______|______|
| thirdPatch | | | |
| secondPatch | x | | |
|_firstPatch__|_____|______|______|
I understand how I could use a while()
loop to build the table headers. And I understand how I could use a while()
to build the rows.
echo "<tr>";
while ($env = $listEnvs->fetch_assoc()){
echo "<th>".$env['name']."</th>"
}
echo "</tr>";
--AND--
while ($patch = $listPatches->fetch_assoc()){
echo "<tr><td>".$patch['name']."</td></tr>";
}
What I am struggling with is that the cells for each patch/environment pair are going to have data that is pulled from several other tables. So knowing the patch.id
as well as the environment.id
is important. Example the cell with the x
is patch.id = 2, environment.id = 1
When constructing the table, how can I make sure each cell has this necessary information?