PHP Overload

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']."<**br><**br>";
$output.= "&inhoud".$i."=".$row['inhoud'];

print $output;
}
?>

Now when I tested the movie, it didn’t work. So I viewed the php file, and this HUGE list comes up, which just grows longer and longer. It almost overloads my computer. What do I have to do to prevent this ?

you’re causing an infinite loop i assume… try this:

$row = mysql_fetch_array($qr);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$output="";
$output.= "&i=".$nrows;
$output.= "&img".$i."=".$row['img'];
$output.= "&datum".$i."=".$row['datum']."<br><br>";
$output.= "&inhoud".$i."=".$row['inhoud'];
print $output;
}

Nope :-\

oh… i think the query’s wrong…

$qr = mysql_query("SELECT * FROM news WHERE <criteria>");

Still nothing :-\ Thanks for your help though :slight_smile: Am I supposed to change <**criteria> with something ? If so, what ?

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/voetsjoeba/HTML/test/news.php on line 7

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/voetsjoeba/HTML/test/news.php on line 8

lol the line i gave doesnt work, you need to put your own criteria in there :slight_smile:

Yeah, but what !? I have four columns, called, newsID, img, datum and title.

what exactly are you trying to extract out of the db??

put the


print output;

outside of your for loop not inside it.

code should look like this


<?
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']."<br><br>";
$output.= "&inhoud".$i."=".$row['inhoud'];
}

print $output;
?>

because you are telling the loop to print out the string output every time the loop executes and the loop gets bigger and bigger with each loop. thats why it prints out so much info.

Well basically … only the text :stuck_out_tongue: That would be ‘datum’ and ‘inhoud’. The image that should be loaded is “home”+i+".jpg", where i = $nrows. So that basically means that if I create another row (with other content), it goes to home2.jpg, and so on.

Now that I think about it, the ‘<**br><**br>’ I have there is totally useless, as the PHP is only defining vars for Flash, and not filling in the vars in Flash … and the ‘img’ column is useless too …

hm… i usually echo the outputed data IN the loop, but no such thing happens :slight_smile:

[edit]

ok i see, since he doesnt have a criteria to be met, he’ll need to have the print function outside the loop… am i getting it right? lol

Didn’t notice your post Jubba :slight_smile: Going to try it now …

not necessarily. I think its just because he is storing all the data inside that string and then telling the loop to print out that string with each loop. You don’t realyl want that. You want to add all the data to the loop and then once the loop is finished print out the data.

No it still doesn’t work. The PHP file now generates the whole loop, and is then supposed to write that whole bunch, but I didn’t wait for that :P. Can I fix the loop somehow ?

can you give us a link to the PHP file? so we can see what its printing out?

which code are you using?

*Originally posted by Jubba *
**not necessarily. I think its just because he is storing all the data inside that string and then telling the loop to print out that string with each loop. You don’t realyl want that. You want to add all the data to the loop and then once the loop is finished print out the data. **

And how would I do that :-\ ?

you have to wait for the loop to finish executing and then print out the data as one long string so Flash can read it. Use the code that I gave you in one of my previous posts.

Well, right now I’m using:


<?
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;
?>

and the link is http://voetsjoeba.xszone.nl/test/news.php. Right now it does nothing, cuz it’s still in that loop, and keeps generating data and thus doesn’t print anything (I guess, cuz I ain’t waiting for it )