# PHP Overload

**URL:** https://forum.kirupa.com/t/php-overload/24829
**Category:** programming
**Created:** [July 5, 2003, 4:32pm UTC](https://forum.kirupa.com/t/php-overload/24829 "2003-07-05T16:32:43Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Voetsjoeba](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@Voetsjoeba](https://forum.kirupa.com/u/Voetsjoeba)
#### Post date: [July 5, 2003, 4:32pm UTC](https://forum.kirupa.com/t/php-overload/24829/1 "2003-07-05T16:32:43Z")

</div>

Hi everyone 🙂

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:

```php
<?
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 ?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:03pm UTC](https://forum.kirupa.com/t/php-overload/24829/2 "2003-07-05T17:03:39Z")

</div>

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

```php
$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;
}

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:14pm UTC](https://forum.kirupa.com/t/php-overload/24829/3 "2003-07-05T17:14:44Z")

</div>

Nope :-\

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:18pm UTC](https://forum.kirupa.com/t/php-overload/24829/4 "2003-07-05T17:18:31Z")

</div>

oh… i think the query’s wrong…

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

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:32pm UTC](https://forum.kirupa.com/t/php-overload/24829/5 "2003-07-05T17:32:17Z")

</div>

Still nothing :-\ Thanks for your help though 🙂 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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:33pm UTC](https://forum.kirupa.com/t/php-overload/24829/6 "2003-07-05T17:33:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:33pm UTC](https://forum.kirupa.com/t/php-overload/24829/7 "2003-07-05T17:33:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:42pm UTC](https://forum.kirupa.com/t/php-overload/24829/8 "2003-07-05T17:42:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:43pm UTC](https://forum.kirupa.com/t/php-overload/24829/9 "2003-07-05T17:43:20Z")

</div>

put the

```php

print output;

```

outside of your for loop not inside it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:46pm UTC](https://forum.kirupa.com/t/php-overload/24829/10 "2003-07-05T17:46:10Z")

</div>

code should look like this

```php

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:46pm UTC](https://forum.kirupa.com/t/php-overload/24829/11 "2003-07-05T17:46:23Z")

</div>

Well basically … only the text 😛 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 …

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:47pm UTC](https://forum.kirupa.com/t/php-overload/24829/12 "2003-07-05T17:47:10Z")

</div>

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

[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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:48pm UTC](https://forum.kirupa.com/t/php-overload/24829/13 "2003-07-05T17:48:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:49pm UTC](https://forum.kirupa.com/t/php-overload/24829/14 "2003-07-05T17:49:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:51pm UTC](https://forum.kirupa.com/t/php-overload/24829/15 "2003-07-05T17:51:30Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:51pm UTC](https://forum.kirupa.com/t/php-overload/24829/16 "2003-07-05T17:51:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:52pm UTC](https://forum.kirupa.com/t/php-overload/24829/17 "2003-07-05T17:52:27Z")

</div>

which code are you using?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:53pm UTC](https://forum.kirupa.com/t/php-overload/24829/18 "2003-07-05T17:53:13Z")

</div>

> \*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 :-\ ?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:54pm UTC](https://forum.kirupa.com/t/php-overload/24829/19 "2003-07-05T17:54:18Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 5, 2003, 5:55pm UTC](https://forum.kirupa.com/t/php-overload/24829/20 "2003-07-05T17:55:25Z")

</div>

Well, right now I’m using:

```php

<?
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](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 )

[Next page](https://forum.kirupa.com/t/php-overload/24829.md?page=2)
