Page 1 of 1

Generating XML from PHP

Posted: Tue Nov 12, 2002 11:49 pm
by gilliepit
I am trying to generate an XML document using PHP pulling down a table from a MySQL database - though there has to be something I'm missing - what I'm doing now is something like this...

Code: Select all

<?php
echo "<?xml version='1.0' encoding='ISO-8859-1' ?>";
echo "<list>";
	
$result = mysql_query("SELECT * FROM table ORDER BY ID DESC");
while($i=mysql_fetch_array($result))
{

  $ID = $iї"ID"];
  $firstname = $iї"firstname"];
  $lastname = $iї"lastname"];

  echo "<person>";
  echo "<ID>$ID</ID>";
  echo "<firstname>$firstname</firstname>";
  echo "<lastname>$lastname</lastname>";
  echo "</person>";

}

echo "</list>";
?>
I know there is some sort of mysql xml dump function out there, but I'm looking to generate it in the way I've specified above if at all possible.. any input would be much appreciated!

And if my question screams idiocy, I'm sorry!! :D

Posted: Wed Nov 13, 2002 2:05 am
by volka
though there has to be something I'm missing
because .....?

you should let a webbrowser (if any) know that you're outputting xml via header('Content-type: text/xml');, then it should show you xml-errors (if any)