Consulta MySQL com While
Tenho uma consulta de MySQL em que com a função "while" faço a separação por meses de umas provas de cicloturismo.
Porém dá-me 2 erros:
1 - Quando a função while está a decorrer e está ao mesmo tempo a limitar a consulta do MySQL o mês de Agosto no While faz corresponder ao mês de Julho no MySQl
2 - Em Dezembro aparece-me 2 linhas da consulta de MySQL
Se quiserem ver a página para entender é: Este é o link
O Código é este:
PHP
[*]
[*]<?
[*]include"conexao.php";
[*]$dat = 1;
[*]$estilo = "h3";
[*]
[*]while ($dat <= 12) {
[]$sql = mysql_query("SELECT from provas WHERE extract(month from inicio) = $dat order by inicio ASC");
[*]
[*]if ($dat==1) echo "<$estilo>Janeiro </$estilo>";
[*]else if ($dat==2) echo "<$estilo>Fevereiro </$estilo>";
[*]else if ($dat==3) echo "<$estilo>Março </$estilo>";
[*]else if ($dat==4) echo "<$estilo>Abril </$estilo>";
[*]else if ($dat==5) echo "<$estilo>Maio </$estilo>";
[*]else if ($dat==6) echo "<$estilo>Junho </$estilo>";
[*]else if ($dat==7) echo "<$estilo>Julho </$estilo>";
[*]else if ($dat==8) echo "<$estilo>Agosto </$estilo>";
[*]else if ($dat==9) echo "<$estilo>Setembro </$estilo>";
[*]else if ($dat==10) echo "<$estilo>Outubro </$estilo>";
[*]else if ($dat==11) echo "<$estilo>Novembro </$estilo>";
[*]else if ($dat==12) echo "<$estilo>Dezembro </$estilo>";
[*]
[*]if(!$sql){echo mysql_error();exit();}
[*]?>
[*]
[*]<table width="80%" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#FFFFFF">
[*]<tr>
[*]<td width="14%" class="title"><div align="center"> Dia </div>
[*] </div></td>
[*]<td width="57%" class="title"><div align="center">Competição
[*] </div>
[*] </div></td>
[*]<td width="14%" class="title"><div align="center">Inicio
[*] </div>
[*]</div></td>
[*]<td width="15%" class="title"><div align="center">Termo
[*] </div>
[*]</div></td>
[*]</tr>
[*]<tr>
[*]<?
[*]while($linha=mysql_fetch_array($sql)) {
[*]?>
[*]<td valign="top"><?=$linha["inicio"]?>
[*]</td>
[*]<td valign="top" class="newstitulo"><?=$linha["designacao"]?></td>
[*]<td valign="top"> <div align="center"></div></td>
[*]<td align="right" valign="top"> <div align="center"></div></td>
[*] </tr>
[*]<tr>
[*] <td colspan="4"><hr></td>
[*] </tr>
[*]<?
[*]}
[*]echo"<br>";
[*]++$dat;
[*]}
[*]?>
[*]</table>
[*]<?
[*]mysql_close($conexao);
[*]?>
[*]
Agradecia se me pudessem ajudar
Discussão (5)
Carregando comentários...