loadVariables

Hi everyone :slight_smile:

I am trying to get data from a MySQL database into Flash. In flash, I have
[AS]
loadVariables(“news.php”,“content”);
[/AS]

on the first frame of the main movie where content is the movieclip the variables should be loaded into. Inside content, I have a dynamic text field with the var ‘inhoud’. On the left of that dynamic textfield, there is an empty movieclip called ‘img’, in which an image should load. So on that movieclip I have

[AS]
onClipEvent(load){
_parent.img.loadMovie(“home”+i+".jpg");
}
[/AS]

Now, the php file “news.php” contains the following:

<?
mysql_connect("localhost", "voetsjoeba","--hidden--");
mysql_select_db("voetsjoeba");

$qr = mysql_query("SELECT * FROM news");

$nrows = mysql_num_rows($qr);
for ($i=0; $i < $nrows; $i++){
$row = mysql_fetch_array($qr);

$output="";
$output.= "&i=".$nrows;
$output.= "&img".$i."=".$row['img'];
$output.= "&datum".$i."=".$row['datum'];
$output.= "&inhoud".$i."=".$row['inhoud'];
}

print $output;
?>

( Thanks a million to Jubba for helping me out with the PHP :love: )

This doesn’t work. Why not ?

getURL(url, target, METHOD)
mthod: POST or GET

he’s trying to load the data into Flash. Not display the PHP page.

I can see many errors… besides, use LoadVars


lv = new LoadVars()
lv.onLoad = function(success) {
if (success) {
i = this.i;
trace(i)
img = this.img;
trace(img);
datum = this.datum;
trace(datum);
inhoud = this.inhoud;
trace(inhoud);
_root[img].loadMovie("home"+i+".jpg");
} else {
trace("failed to load script");
}
}
lv.load("news.php")

try that, let me know how it goes :slight_smile:

Ok, I’ll try that :slight_smile: Thanks ahmed :slight_smile:

A part works ! :stuck_out_tongue: I added an extra textfield on top to display the amount of rows. In that textbox, it is supposed to fill in the value of the varibale “i”, which it got out of the PHP script. This is a good sign, because I know now that it did recieve the variables. But the other fields didn’t get filled in … Is it possible that I have to change “datum = this.datum” to “this.datum = datum” ? I’m not sure what the variable is and what the path to the textfield is here … :stuck_out_tongue:

*Originally posted by Voetsjoeba *
**is it possible that I have to change “datum = this.datum” to “this.datum = datum” ? I’m not sure what the variable is and what the path to the textfield is here … :stuck_out_tongue: **
no… can i see a dummy FLA?

Well, I’ve set up a SWF online to test he variables, you can see it here: http://voetsjoeba.xszone.nl/test/test.html and the swf fle is http://voetsjoeba.xszone.nl/test/test.swf . Maybe the SWF is better to see, cuz the font size is quite small …

It fills in i (3), which is correct, but it doesn’t recognise the other variables, ‘inhoud’ en ‘datum’. I’ll post the dummy FLA in a sec.

$output="";
$output.= "&i=".$nrows;
$output.= "&img".$i."=".$row['img'];
$output.= "&datum".$i."=".$row['datum'];
$output.= "&inhoud".$i."=".$row['inhoud'];
}

if you get rid of the $i, it would work :slight_smile:

Thanks =) Lemme try.

[EDIT] It works !!! Thank you thank you thank you !![/EDIT]