Jump to content

xml creation problem


beermaker74

Recommended Posts

I have this script that I am playing with to create an xml file from a mysql query

[code=php:0]<?php

$file= fopen("results.xml", "w");

$xml_output  = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<gallery>\n";

for($x = 0 ; $x < mysql_num_rows($Recordset1) ; $x++){
    $totalRows_Recordset1 = mysql_fetch_assoc($Recordset1);
    $xml_output .= "\t<listings>\n";
    $xml_output .= "\t\t<houseid>" . $totalRows_Recordset1['houseid'] . "</houseid>\n";
    $xml_output .= "\t\t<username>" . $totalRows_Recordset1['username'] . "</username>\n";
$xml_output .= "\t\t<address>" . $totalRows_Recordset1['address'] . "</address>\n";
    $xml_output .= "\t</listings>\n";
}

$xml_output .= "</gallery>";

fwrite($file, $xml_output);

fclose($file);

echo "XML has been written.  <a href=\"results.xml\">View the XML.</a>";

?>
[/code]

here is the result of a query with one record
<gallery>
<listings>
<houseid/>
<username/>
<address/>
</listings>
</gallery>

the result is not listed.
Here is the result of a query with 2 records

<gallery>
<listings>
<houseid>26</houseid>
<username>jerry</username>
<address>55 fake ave</address>
</listings>
<listings>
<houseid/>
<username/>
<address/>
</listings>
</gallery>

there is 2 records in that query. For some reason it is only outputing anything over 1 record. yet it is displaying blank tags

if you see my problem please let me know. I am just trying to write from a simple query now. MY real task is to write the xml from a more advanced query. So I need to figure out the simple problem first
thanks
Link to comment
https://forums.phpfreaks.com/topic/36286-xml-creation-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.