# Flash, PHP, and MySQL Integration example

**URL:** <https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325>\
**Category:** programming\
**Created:** [April 20, 2006, 3:15pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325 "2006-04-20T15:15:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gordonb](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@gordonb](https://forum.kirupa.com/u/gordonb)\
**Post date:** [April 20, 2006, 3:15pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/1 "2006-04-20T15:15:39Z")

</div>

Hi, I’m tryin to get my head around flash and find this site a great help.

I can’t get the [COLOR=black]Flash[FONT=Verdana], PHP, and MySQL Integration example to work- the one where an action script calls a php script to get data from the MySQL database to display in a swf page.[/FONT][/COLOR]  
[COLOR=black][FONT=Verdana][/FONT][/COLOR]  
[COLOR=black][FONT=Verdana] I know the php/MySQL part is working and I can see the data on the sites.php page but nothing appears on the sites.swf page. I even tried downloading your code and used this in place of my typed example, but still nothing appears in the swf page. [/FONT][/COLOR]  
[COLOR=black][FONT=Verdana][/FONT][/COLOR]  
[COLOR=black][FONT=Verdana]Can anyone put me out of my misery ?[/FONT][/COLOR]

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 20, 2006, 3:25pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/2 "2006-04-20T15:25:59Z")

</div>

post your code, and also a link to the php that is displaying the information:)

---

<div class="post-metadata">

**Author:** ![gordonb](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@gordonb](https://forum.kirupa.com/u/gordonb)\
**Post date:** [April 20, 2006, 6:24pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/3 "2006-04-20T18:24:53Z")

</div>

Thanks for the quick reply, here is how I understood the article at

[http://www.kirupa.com/developer/actionscript/flashphpxml\_integration.htm](http://www.kirupa.com/developer/actionscript/flashphpxml_integration.htm)

the fla file has just 1 text box.

This is set as - dynamic text, instance name= sites\_txt, multiline, render as html.

There are 2 layers, one with the text box and the other with the action script.  
Frame 1 of the action script= #include “sites.as”

This loads this externl actionscript file…

function lv(l, n, t, e, f) {  
if (l == undefined) {  
l = new LoadVars();  
l.onLoad = function() {  
var i;  
n.htmlText = “”;  
if (t == undefined) {  
n.htmlText += “\<b\>”+this[“title”+e]+"\</b\>\<br\>";  
} else {  
for (i=0; i\<this.n; i++) {  
n.htmlText += “\<class=‘menu\_item’\>\<a href=’”+this[“link”+i]+"’\>"+this[“title”+i]+"\</a\>\<br\>";  
}  
}  
};  
}  
l.load(f);  
}  
lv(sites\_txt, “cycle”, null, “sites.php”);

I’m sure the MySQL/PHP part is OK as the script.php code generates this…

&n=12&id0=3&&title0=Canned\_Laughter&&link0=http://www.cannedlaughter.net&&id1=4&&title1=Voetsjoeba&&link1=http://www.voetsjoeba.com&&id2=5&&title2=Kirupa&&link2=http://www.kirupa.com&&id3=6&&title3=Spoono&&link3=http://www.spoono.com&&id4=7&&title4=ReadyMadeMag&&link4=http://www.readymademag.com&&id5=9&&title5=Weebl and Bob&&link5=http://www.weebl.jolt.co.uk&&id6=10&&title6=Link 10&&link6=http://www.aamukaste.org&&id7=12&&title7=Flip Flop Flyin&&link7=http://www.flipflopflyin.com&&id8=15&&title8=KirupaForum&&link8=http://www.kirupaforum.com&&id9=16&&title9=Razyr&&link9=http://www.razyr.com/blog&&id10=17&&title10=Senocular&&link10=http://senocular.com&&id11=18&&title11=May 1st Reboot&&link11=http://www.may1reboot.com&&

the script.php file ( without my db comnnection info) is …

\<?php  
mysql\_pconnect (“MY DATABASE CONNECTION DETAILS ARE IN HERE”);

mysql\_select\_db (“MY DATABASE”);  
$qResult = mysql\_query (“SELECT \* FROM sites ORDER BY id ASC”);  
$nRows = mysql\_num\_rows($qResult);  
$rString ="&n=".$nRows;  
for ($i=0; $i\< $nRows; $i++){  
$row = mysql\_fetch\_array($qResult);  
$rString .="&id".$i."=".$row[‘id’]."&"."&title".$i."=".$row[‘title’]."&".  
"&link".$i."=http://".$row[‘link’]."&";  
}  
echo $rString."&";

?\>

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 20, 2006, 6:32pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/4 "2006-04-20T18:32:22Z")

</div>

> &n=12&id0=3&&title0=Canned\_Laughter&&link0=http ://www.cannedlaughter.net&&id1=4&&title1=Voetsjoeba&& link1=[http://www.voetsjoeba.com](http://www.voetsjoeba.com)&&id2=5&&title2=Kirupa&&link2=ht tp://www.kirupa.com&&id3=6&&title3=Spoono&&link3=[http://www.spoono.com](http://www.spoono.com)&&id4=7&&title4=ReadyMadeMag&&link4= [http://www.readymademag.com](http://www.readymademag.com)&&id5=9&&title5=Weebl and Bob&&link5=[http://www.weebl.jolt.co.uk](http://www.weebl.jolt.co.uk)&&id6=10&&title6=Link 10&&link6=[http://www.aamukaste.org](http://www.aamukaste.org)&&id7=12&&title7=Flip Flop Flyin&&link7=[http://www.flipflopflyin.com](http://www.flipflopflyin.com)&&id8=15&&title8=KirupaForum& &link8=[http://www.kirupaforum.com](http://www.kirupaforum.com)&&id9=16&&title9=Razyr&&link9=h ttp://www.razyr.com/blog&&id10=17&&title10=Senocular&&link10=[http://senocular.com](http://senocular.com)&&id11=18&&title11=May 1st Reboot&&link11=[http://www.may1reboot.com](http://www.may1reboot.com)&&

I notice this is splitting to the next line, did you paste it that way or is that what it actually outputs, LoadVars wants a single long a\*\* string.  
Also:

```auto
function lv(l, n, t, e, f) {
//5 variables
lv(sites_txt, "cycle", null, "sites.php");
//4 variables

```

hmm… that means that:

```auto
e == "sites.php"
//&
f == "undefined"

```

&

```auto
l.load("undefined");

```

I dont think thats gonna work out too well:)

---

<div class="post-metadata">

**Author:** ![gordonb](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@gordonb](https://forum.kirupa.com/u/gordonb)\
**Post date:** [April 20, 2006, 6:55pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/5 "2006-04-20T18:55:17Z")

</div>

> I notice this is splitting to the next line, did you paste it that way or is that what it actually outputs, LoadVars wants a single long a\*\* string.  
> Also:

ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#000000] **function** [/COLOR] lv[COLOR=#000000]([/COLOR]l, n, t, [COLOR=#0000ff]e[/COLOR], f[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#808080]_//5 variables_[/COLOR]  
lv[COLOR=#000000]([/COLOR]sites\_txt, [COLOR=#ff0000]“cycle”[/COLOR], [COLOR=#000000] **null** [/COLOR], [COLOR=#ff0000]“sites.php”[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#808080]\*//4 variables \*[/COLOR]

[/LEFT]  
[/FONT]

It’s one long string.

I don’t know much about actionscript but now you point it out  
f has not been defined so the line …

l.load(f); [or new Load Vars.load(f)] aint gonna send much back to flash.

Any suggestions for the missing part ??:}

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 20, 2006, 7:13pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/6 "2006-04-20T19:13:22Z")

</div>

well, alot of it seems pretty redundant. Try shaving it like this:

```auto
function lv(n, e, f) {
   var List:LoadVars = new LoadVars();
   List.sendAndLoad(f, List, "POST");
   List.onLoad = function() {
      n.htmlText = "";
      for (i=0; i<this.n; i++) {
         n.htmlText += "<a href='"+List["link"+i]+"'>"+Link["title"+i]+"</a><br>";
      }
   }
}

lv("cycle", null, "sites.php");

```

just try it basic, then add things until it all works.

---

<div class="post-metadata">

**Author:** ![gordonb](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@gordonb](https://forum.kirupa.com/u/gordonb)\
**Post date:** [April 20, 2006, 7:41pm UTC](https://forum.kirupa.com/t/flash-php-and-mysql-integration-example/186325/7 "2006-04-20T19:41:43Z")

</div>

No it’s still not working. Thanks Defective for you help, I’ll just have to find a plan B
