<?php
include("conexao.inc.php");

// Buscando as escolas de origem
$sql = "SELECT DISTINCT origem FROM inscricoes order by origem";
$res = mysqli_query($conexao, $sql ) or die( 'Erro na query: <BR>' . $sql . '<BR>' . mysqli_error() );
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
.txt_form {	font-size: 9px;
	font-weight: bold;
}
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<title>Relatório</title></head>

<body>

<?php
while ($row = mysqli_fetch_array($res)){
		$origem = $row["origem"];
		$sql2 = "select * from inscricoes where origem = '$origem' order by id";
		$res2 = mysql_query($sql2);
		echo "<p>ESCOLA DE ORIGEM : <strong>$origem</strong></p>"
?>
<table width="100%" border="1">
  <tr>
    <td>N&ordm; da Inscri&ccedil;&atilde;o</td>
    <td>Nome</td>
    <td>Unidade pretendida</td>
    <td>Origem</td>
    <td>Data da Inscri&ccedil;&atilde;o</td>
  </tr>
<?php
while ($row2 = mysql_fetch_array($res2)){
?>
  <tr>
    <td><?php echo $row2["inscricao"];?></td>
    <td><?php echo $row2["nome"];?></td>
    <td><?php echo $row2["unidade"];?></td>
    <td><?php echo $row2["origem"];?></td>
    <td><?php echo date('d/m/Y', strtotime($row2["data_inscricao"]));?></td>
  </tr>
<?php } ?>
</table>

<p><strong>Total de Inscritos: </strong><?php echo mysql_num_rows($res2);?></p>
<?php } ?>

</body>
</html>
