Problem formatting MySQL query results as XML.

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
lgmcben
Forum Newbie
Posts: 2
Joined: Sun Nov 02, 2008 12:54 pm

Problem formatting MySQL query results as XML.

Post by lgmcben »

Hi, I'm trying to communicate with MySQL using PHP.

Actually I was following this:

http://livedocs.adobe.com/flex/3/html/d ... tml#193905



And here are the problem lines:
//////////////////////////////////////////////////////////////////////////
while ( $User = mysql_fetch_object( $Result ) )
{
$Return .= "<user><userid>".$User->userid."</userid><username>".$User->username."</username><emailaddress>".$User->emailaddress."</emailaddress></user>";
}
$Return .= "</users>";
mysql_free_result( $Result );
print ($Return)
//////////////////////////////////////////////////////////////////////////

I tried populating my table with some values before hand. (like samplename, sampleemail, ...)

After I run this php script(I didn't even involve with Flex yet, that's why I post here), the browser show something like this:

"1samplenamesamplemail2samplename2samplemail2" (of course, without the quotes)

instead of something like this:

<user>
<userid>1</userid>
<username>samplename</username>
<emailaddress>sampleemail</emailaddress>
</user>"
<user>
<userid>2</userid>
<username>samplename2</username>
<emailaddress>sampleemail2</emailaddress>
</user>"

What did I do wrong?

Thank you in advance. =)
zephyr750
Forum Newbie
Posts: 6
Joined: Sat Nov 01, 2008 8:05 am

Re: Problem formatting MySQL query results as XML.

Post by zephyr750 »

I have a feeling that you are doing nothing wrong. The browser is just processing the xml tags as HTML so the tags are not being displayed. Try viewing the source of you browser, you may find that the tags are there.
cboileau
Forum Newbie
Posts: 8
Joined: Sun Nov 02, 2008 8:28 am

Re: Problem formatting MySQL query results as XML.

Post by cboileau »

zephyr750 wrote:I have a feeling that you are doing nothing wrong. The browser is just processing the xml tags as HTML so the tags are not being displayed. Try viewing the source of you browser, you may find that the tags are there.
If you want the output to display as XML, simple add this to the top of your PHP script.

Code: Select all

header('Content-Type: text/xml');
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: Problem formatting MySQL query results as XML.

Post by pavanpuligandla »

hii..
i think u need to include php xml parser to read those values and displaying them in xml format.
c this,. http://in.php.net/manual/en/book.xmlwriter.php
Post Reply