i've had some good help on this forum in the last couple
of days but i still havent been able to make this work
yet. i'm trying to use php (4.06) to write to an xml document
usind data and fieldnames from a psql database. the php
script is generating xml, its writing the whole document
in fact but the structure is wrong. It prints a record for
correct number of fields but it repeats the details twice
and then appears to get stuck in a loop after it reaches the
second field. the other problem is that i still cannot get
the fieldnames inside the xml tags.
I really appreciate the help i've been given and any other
help people can offer to help me make this work.
<?php
$conn = pg_connect("");
if (!$conn)
{
echo "<h1>Connection Error</h1>";
exit;
}
$sql="SELECT * FROM flock;";
$result_set = pg_exec($conn, $sql);
$rows = pg_numrows($result_set);
for ($j=0; $j<$rows; $j++)
{
list($flock_number,$flock_location) = pg_fetch_row($result_set, $j);
}
$file= fopen("flock.xml" , "w");
$_xml .="<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\r\n";
$_xml .="<!-- table flock-->\r\n";
$_xml .="<flock>\r\n";
//$result_set = pg_Exec ($conn, $sql);
for ($j=0; $j<$rows; $j++) {
$row = pg_fetch_array($result_set, $row);
//$row = pg_fetch_object($result_set, $row);
$_xml .=" <record>\r\n";
foreach ($row as $data) {
$_xml .=" <$fieldnames[$count]>$data</$fieldnames[$count]>\r\n";
$count++;
}
$_xml .=" </record>\r\n";
}
//}
$_xml .="</flock>";
fwrite($file, $_xml);
fclose($file);
echo $_xml;
pg_close();
?>
when i try to generate the xml this error comes up:
A name was started with an invalid character. Error processing resource
'../newCheck.php'. Line 5, Position 10
<>1</>
---------^
but when i view the source i see:
<?xml version="1.0" encoding="iso-8859-1" ?>
<!-- table flock-->
<flock>
<record>
<>1</>
<>1</>
<>den</>
<>den</>
</record>
<record>
<>2</>
<>2</>
<>the barn</>
<>the barn</>
</record>
<record>
<>2</>
<>2</>
<>the barn</>
<>the barn</>
</record>
etc. for the number of fields i have.
Thanks again for the help.