Assist cleaning up messy HTML/PHP code
WKS is right, first of all you should split your layout from your logic and your logic from your database query. (see Model-View-Controller-Pattern)

Lets start with your model (Model.php): (actually you could split it in a model for each entity/database table)

&lt;?php
class Model()
{
     public function __construct(PDO $connection)
     {
         $this-&gt;connection=connection;
     }

     public function getZones($week)  //find a nicer name
     {
         //... see Peters post for a sample join
         // prepare multi dimensional array as needed in your template
         return $zones;
     }
}


It is in general a bad idea to run SQL queries in a loop, so try to create one join for all your queries.

Now the simple Controller (index.php)

&lt;?php
require 'Model.php';
$connection=new PDO(...);
$model=new Model($connection);
$currentWeek = ...;
$zones= $model-&gt;getZones($currentWeek);

include "view.php"


That's it! Nothing fancy. Now the view:

&lt;table&gt;
    &lt;tr&gt;
         &lt;th&gt;Zona&lt;/th&gt;
         &lt;th&gt;Baptismos Mulheres&lt;/th&gt;
         &lt;th&gt;Conf. Mulheres&lt;/th&gt;
         &lt;th&gt;Batismos Homems&lt;/th&gt;
         &lt;th&gt;Conf. Homems&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php foreach($zones as $zone):?&gt;
    &lt;tr&gt;
         &lt;td&gt;&lt;?php echo $zone['name']; ?&gt;&lt;/td&gt;
         &lt;td colspan="4"&gt;&lt;/td&gt;
    &lt;/tr&gt;                   
        &lt;?php foreach($zones['areas'] as $area):?&gt;
        &lt;tr&gt;
            &lt;td&gt;
                 &lt;?php $area['name']; ?&gt; &lt;?php echo $area['companions']; ?&gt;
            &lt;/td&gt;
            &lt;td colspan="4"&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;?php endforeach?&gt;
    &lt;?php endforeach?&gt;
&lt;/table&gt;


Don't use all-capital-letter variable names. And don't use global variables. Both is considered bad practice.