0
I have a PHP script that generates XML file, but something very strange is that it repeats several records of my real estate table and the worst thing is that there are no repeated properties. Repeats the property ID where there is only one property for each ID.
Follow my code that generates XML:
$arquivo = "nuroa.xml";
$ponteiro = fopen($arquivo, "w");
fwrite($ponteiro, "<?xml version='1.0' encoding='utf-8'?>");
fwrite($ponteiro, '<nuroa>');
$sqlguiatexto = "SELECT id FROM imoveis";
$rsqlguiatexto = mysql_query($sqlguiatexto)
or die ("Não foi possível realizar a consulta ao banco de dados");
while($roweditusertexto = mysql_fetch_array($rsqlguiatexto))
{
$conteudo .= '<ad>';
$conteudo .= '<id><![CDATA['.$roweditusertexto['id'].']]></id>';
$conteudo .= '</ad>';
fwrite($ponteiro, $conteudo);
}
fwrite($ponteiro, '</nuroa>');
fclose($ponteiro);
Can anyone tell me what’s going on for this? Strange is that there is no repeat record.
I’m waiting for help, thank you very much!
How do I solve?
– Gladison Neuza Perosini
@Gladisonneuzaperosini the code in the answer is already the solution. Instead of just adding things up in the content, we are recreating it with each data. Look at the difference in
$conteudo
of the first line. In the first line=
in place of.=
- I edited the comment in the code for you to find the difference.– Bacco
Thank you very much! It worked perfectly.
– Gladison Neuza Perosini