Flash, PHP, and MySQL Integration example

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]

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

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

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."&";

?>

&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=ht tp://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=h ttp://www.razyr.com/blog&&id10=17&&title10=Senocular&&link10=http://senocular.com&&id11=18&&title11=May 1st Reboot&&link11=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:

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

hmm… that means that:

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

&

l.load("undefined");

I dont think thats gonna work out too well:)

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 ??:}

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

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.

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