I really hate messy code, but I seem to be rolling in it. I just want to see if anyone has some helpful advice on how to tidy this up.
<table>
<tbody>
<tr>
<th>Zona</th>
<th>Baptismos Mulheres</th>
<th>Conf. Mulheres</th>
<th>Batismos Homems</th>
<th>Conf. Homems</th>
</tr>
<?php
$currWeek = $CONF->getSetting('current_week');
$zones = $PDO->query("SELECT * FROM zones WHERE active = 1");
foreach($zones as $zone) {
$zoneName = $zone['name'];
$zoneUid = $zone['uid'];
?>
<tr>
<td><?php print $zoneName; ?></td>
</tr>
<?php
$areas = $PDO->query("SELECT * FROM areas WHERE zone = '".$zoneUid."'");
foreach($areas as $area) {
$areaName = $area['name'];
$areaUid = $area['uid'];
?>
<tr>
<td><?php print $areaName; ?>
<?php
$missionaries = $PDO->query("SELECT missionary FROM missionary_areas WHERE semana = '".$currWeek."' AND area_uid = '".$areaUid."'");
$compArr = array();
foreach($missionaries as $missionary) {
$companions = $PDO->query("SELECT CONCAT(title, ' ', mission_name) as name from missionarios WHERE mid = '".$missionary['missionary']."'");
foreach($companions as $comp) {
$compArr[] = $comp['name'];
}
}
$compList = $CONF->commaSeparate($compArr);
?>
<?php print $compList; ?></td>
<td></td>
<td></td>
<td></td>
<td></td>
<?php
}
}
?>
I am still a bit inexperienced and would like some helpful tips. My MySQL directory stucture is necessaraly crazy so I have to do a bunch of queries to get some simple data. Using PDO is helping quite a bit though.
Edit:
Database structure