Generating XML from PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gilliepit
Forum Newbie
Posts: 9
Joined: Sat Oct 12, 2002 12:52 pm
Location: usa.sc.cola
Contact:

Generating XML from PHP

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)
Post Reply