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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.