# (AS2) mySQL, PHP, convert to XML pass to Flash

**URL:** <https://forum.kirupa.com/t/as2-mysql-php-convert-to-xml-pass-to-flash/273438>\
**Category:** programming\
**Created:** [October 15, 2008, 3:29pm UTC](https://forum.kirupa.com/t/as2-mysql-php-convert-to-xml-pass-to-flash/273438 "2008-10-15T15:29:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ty88](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@ty88](https://forum.kirupa.com/u/ty88)\
**Post date:** [October 15, 2008, 3:29pm UTC](https://forum.kirupa.com/t/as2-mysql-php-convert-to-xml-pass-to-flash/273438/1 "2008-10-15T15:29:21Z")

</div>

\*\* Hi

I am a bit of a newcomer who is trying to create a flash file that displays the top 5 highest rated songs (stored in a mySQL database) in dynamic text boxes. I have most of it done but am having problems using PHP to convert the results into XML to be passed to Flash.

I can successfully execute the mySQL query in phpmyAdmin:  
[LEFT]SELECT Track, Artist, Votes FROM shows ORDER BY Votes DESC LIMIT 0, 5[/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]I can also successfully load XML into flash, although i don’t know how to make a loop so the code is terrible (any help here would be great):[/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]function loadXML(loaded) {[/LEFT]  
[LEFT] if (loaded) {[/LEFT]  
[LEFT] \_root.playlist = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;[/LEFT]  
[LEFT] \_root.track = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;[/LEFT]  
[LEFT] \_root.votes = this.firstChild.childNodes[0].childNodes[2].firstChild.nodeValue;[/LEFT]  
[LEFT] artist\_txt.text = \_root.playlist;[/LEFT]  
[LEFT] track\_txt.text = \_root.track;[/LEFT]  
[LEFT] votes\_txt.text = \_root.votes;[/LEFT]  
[LEFT] [/LEFT]  
[LEFT] \_root.playlist = this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;[/LEFT]  
[LEFT] \_root.track = this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;[/LEFT]  
[LEFT] \_root.votes = this.firstChild.childNodes[1].childNodes[2].firstChild.nodeValue;[/LEFT]  
[LEFT] artist2\_txt.text = \_root.playlist;[/LEFT]  
[LEFT] track2\_txt.text = \_root.track;[/LEFT]  
[LEFT] votes2\_txt.text = \_root.votes;[/LEFT]  
[LEFT] [/LEFT]  
[LEFT] etc etc … [/LEFT]  
[LEFT] [/LEFT]  
[LEFT] } else {[/LEFT]  
[LEFT] content = “file not loaded!”;[/LEFT]  
[LEFT] }[/LEFT]  
[LEFT]}[/LEFT]  
[LEFT]xmlData = new XML();[/LEFT]  
[LEFT]xmlData.ignoreWhite = true;[/LEFT]  
[LEFT]xmlData.onLoad = loadXML;[/LEFT]  
[LEFT]xmlData.load(“top5\_votes.xml”);[/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]When I then try and change the file being loaded from an XML file to a PHP file it doesn’t work. I think the problem is with my PHP or making flash communicate with the PHP. This is my code:[/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]\<?php [/LEFT]  
[LEFT]//connect to database[/LEFT]  
[LEFT]include\_once(“config.php”); [/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]$result = mysql\_query(“SELECT Track, Artist, Votes FROM shows ORDER BY Votes DESC LIMIT 0, 5”); [/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]// Output an XML document [/LEFT]  
[LEFT]echo ‘\<?xml version=“1.0” encoding=“UTF-8”?\>’; [/LEFT]  
[LEFT]echo ‘\<datapacket\>’; [/LEFT]  
[LEFT]while($row=mysql\_fetch\_array($result)){ [/LEFT]  
[LEFT] $line = ‘\<row Track="’.$row[Track].’" Artist="’.$row[Artist].’" Votes="’.$row[Votes].’"/\>’; [/LEFT]  
[LEFT] echo $line; [/LEFT]  
[LEFT]} [/LEFT]  
[LEFT]echo ‘\</datapacket\>’; [/LEFT]  
[LEFT]?\> [/LEFT]  
[LEFT]  
[/LEFT]  
[LEFT]Can anyone tell me how I can make this work - i would really appreciate it. Thanks a lot guys![/LEFT]  
\*\*
