While - Returns only one record

0

Because my WHILE is displaying only one record (two records!)

$resultnome = mysql_query("
select DIVU.DIVU_NM_DIVULGACAO, DIVU.DIVU_DS_LOGRADOURO, DIVU.DIVU_DS_NUMERO, DIVU.DIVU_DS_TELEFONES, DIVU.ID_PRESTADOR_DIVULGACAO, SERVI.SERV_NM_SERVICO, TISE.ID
from DIVULGACAO DIVU 
LEFT JOIN SERVICO SERVI ON DIVU.ID = SERVI.ID_DIVULGACAO
LEFT join TIPO_SERVICO TISE ON SERVI.ID_TIPO_SERVICO = TISE.ID
WHERE DIVU.DIVU_NM_DIVULGACAO = 'MeuTexto' AND TISE.ID = 3
") or die(mysql_error());

$rows = mysql_fetch_array($resultnome);
$nomeunidade = $rows['DIVU_NM_DIVULGACAO'];
$enderecounidade = $rows['DIVU_DS_LOGRADOURO'];
$numerounidade = $rows['DIVU_DS_NUMERO'];
$telefoneunidade = $rows['DIVU_DS_TELEFONES'];

echo '<strong>'.$nomeunidade.'</strong><br>';

while($rows = mysql_fetch_array($resultnome))
  {
    echo $rows['SERV_NM_SERVICO'];
  }

echo '<br><span class="glyphicon glyphicon-map-marker"></span> '.$enderecounidade.', '.$numerounidade.'<br>';
echo '<span class="glyphicon glyphicon-earphone"></span> Tel. '.$telefoneunidade.'<br>';
    
asked by anonymous 14.04.2015 / 19:23

1 answer

4

The problem is that you are already using the mysql_fetch_array function before the loopback, ie you have already obtained a record, and while will start in the second. A simple solution is to use do...while :

do {
    echo $rows['SERV_NM_SERVICO'];
} while ($rows = mysql_fetch_array($resultnome));

Note that you can only use this solution because you are already getting the first result before the loopback.

    
14.04.2015 / 21:37