# Displaying Images In Flash From Mysql

**URL:** <https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703>\
**Category:** programming\
**Created:** [July 15, 2003, 9:37pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703 "2003-07-15T21:37:30Z")\
**Posts on this page:** 6\
**Page:** 2

<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:** [August 12, 2003, 8:25am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/21 "2003-08-12T08:25:08Z")

</div>

zam’ , do you realize this has been going on for a whole month now 🙂 ?  
why do you need the db anyway?

use this:

```php
 <?php
// pass in:
// $dir - directory to search
// $ext - extention to use - blank for all

$dh = @opendir ($dir);
while ($file = @readdir ($dh)) {
	if(($file!="..")&&($file!=".")){
		$entry = "$dirpath/$file";
		$path_parts = pathinfo($entry);
		$type=$path_parts["extension"];
		if ((strtoupper($type)==strtoupper($ext)) || (!$ext)) {
			if ($output!="") $output .= "|";
			$output.=$file;
		}
	}
}
$output.="&status=ok";
echo(utf8_encode("&files=".$output));
?>

```

put in a file named “files.php” (or any name you want), put that in same folder as your swf, from flash, call loadVariables(“files.php?dir=nameOfYourImageFolder”, this) and your done, it will return a list of all the images in that folder to Flash, call the php in your browser to get a look at the output…  
Or does it have to be a 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:** [August 12, 2003, 8:33am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/22 "2003-08-12T08:33:31Z")

</div>

ok I will try this suggestion

I am pulling out my hair over this script!!

I can get text in/out of mysql  
I can get pic from php

but having the darnest hard time with the flash-pjp-mysql image combo!!!

Yes, the pic names must be stored in a database because I am pulling up members information from the database and I need the pictures to correspond with the specific user.

would eventually like to use flash-xml-flash-mysql combo  
but I need for the first scrpt to work b4 I can proceed

If this code work for me, I will take you out on the town!!

----lol

I’ve spent countless hours trying to get this to work

SOOOOO CLLLOOOOSSSSEEEEEEEEE

— will let u no what happens

---

<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:** [August 12, 2003, 9:31am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/23 "2003-08-12T09:31:14Z")

</div>

ok

getting closer here

I tried your suggestion  
and I am getting the string

“&status=ok”

## I followed your specific direction!!!

Tried different cobimations after that like:

\<?PHP  
$Connect = mysql\_pconnect($localhost, “”, “”) or die(mysql\_error());  
mysql\_select\_db(“aboy”, $Connect);  
$result = mysql\_query(“select \* from image”); //just one image  
$image = mysql\_fetch\_array($result);

$dh = @opendir ($dir);  
while ($file = @readdir ($dh)) {  
if(($file!="…")&&($file!=".")){  
$entry = “$dirpath/$file”;  
$path\_parts = pathinfo($entry);  
$type=$path\_parts[“extension”];  
if ((strtoupper($type)==strtoupper($ext)) || (!$ext)) {  
if ($output!="") $output .= “|”;  
$output.=$file;  
}  
}  
}  
$output.="&status=ok";  
echo(utf8\_encode("&files=".$output));

?\>

to connect to the db

I figured this would not work

* * *

I am a newbi!!! —lol

I just need a very very very very basic basic basic easy easy short script just to even get 1. jpg flename out of db

have the pic in a /image folder

and call it up via php n2 flash

This way I can really understand what is happening with the code.

I am not this advanced YET!!! :phil:

I really wanted your last code to work 4 me and I tried it like 15 times —lol

I am sick and crazy!!! 🥚 --lol

wanna c???

---

<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:** [August 13, 2003, 10:53am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/24 "2003-08-13T10:53:40Z")

</div>

OK

After 2 month2 of going online and asking for help and reading every flash book I could get my hands on I have come up with a code that will load .jpg’s from mysql and via filename.

I still do not know how to store the .jpgs in a directory folder name …/images.

This is a major issue with alot of beginners using php,mysql with flash and I am very, very disappointed in the flash forums on the net regarding this isue. Either you get code that is not understandable for beginning-intermmediate folks or for you get tuts that are \<snippits\> , unclear, or not complete. So here, I will post what I came up with for all to view and use!!!

And it works!!!

This script also fetch the the images in grid rows.

I do not know how to write loops and functions yet so there are alot of if’s statements. If someone wants to consolidate this code please post it!!!

The senario:

10 empty mc’s to hold .jpgs on stage

## actionscript

count = 0;

myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {  
pic1.loadMovie(this.pic1);

```
} else {
	trace("error: couldn't load from database");
}

```

};

count = 1;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic2.loadMovie(this.pic2);

} else {
	trace("error: couldn't load from database");
}

```

};

count = 2;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic3.loadMovie(this.pic3);

} else {
	trace("error: couldn't load from database");
}

```

};

count = 3;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic4.loadMovie(this.pic4);
} else {
	trace("error: couldn't load from database");
}

```

};

count = 4;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic5.loadMovie(this.pic5);
} else {
	trace("error: couldn't load from database");
}

```

};

count = 5;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic6.loadMovie(this.pic6);
} else {
	trace("error: couldn't load from database");
}

```

};

count = 6;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic7.loadMovie(this.pic7);
} else {
	trace("error: couldn't load from database");
}

```

};

count = 7;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic8.loadMovie(this.pic8);
} else {
	trace("error: couldn't load from database");
}

```

};

count = 8;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic9.loadMovie(this.pic9);
} else {
	trace("error: couldn't load from database");
}

```

};

count = 9;  
myData = new loadVars();  
myData.load(“abc.php”);  
myData.onLoad = function(success) {  
if (success) {

```
	pic10.loadMovie(this.pic10);
} else {
	trace("error: couldn't load from database");
}

```

};

php script

## abc.php

\<?php  
mysql\_connect(“localhost”,"","");  
mysql\_select\_db(“aboy”);

$query = “SELECT \* FROM image”;  
$result = @mysql\_query($query);

```
$count = "0";
$output = "";

```

while ($row = mysql\_fetch\_array($result)) {

$pic = stripslashes($row[‘pic’]);  
$pic2 = stripslashes($row[‘pic’]);  
$pic3 = stripslashes($row[‘pic’]);   
$pic4 = stripslashes($row[‘pic’]);   
$pic5 = stripslashes($row[‘pic’]);   
$pic6 = stripslashes($row[‘pic’]);   
$pic7 = stripslashes($row[‘pic’]);   
$pic8 = stripslashes($row[‘pic’]);   
$pic9 = stripslashes($row[‘pic’]);   
$pic10 = stripslashes($row["pic’]);

$output .= “&pic” . $count . “=” . urlencode($pic);  
$output .= “&pic2” . $count . “=” . urlencode($pic);  
$output .= “&pic3” . $count . “=” . urlencode($pic);  
$output .= “&pic4” . $count . “=” . urlencode($pic);   
$output .= “&pic5” . $count . “=” . urlencode($pic);   
$output .= “&pic6” . $count . “=” . urlencode($pic);  
$output .= “&pic7” . $count . “=” . urlencode($pic);  
$output .= “&pic8” . $count . “=” . urlencode($pic);  
$output .= “&pic9” . $count . “=” . urlencode($pic);  
$output .= “&pic10” . $count . “=” . urlencode($pic);

$count++;  
}

```
echo $output . "&records=" . $count . "&result=Okay&";

```

?\>

* * *

like I said if anyone can make the code shorter please do it because the code is really “BIGGGGG”

AND if you know how to target the …/images folder let us know.

As of this date: the files are stored in the same directory as the .swf and .php file

Happy trails

and thank you Eyezburg!!!

C:-)

c now I am happy!!!

---

<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:** [August 13, 2003, 12:10pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/25 "2003-08-13T12:10:51Z")

</div>

Ah, zam’, this code is terrible, lol 😉  
Glad you got it working (still wonder how, seeing this, lol…not making fun of ya, i am happy for you!!);  
i was indded thinking of tutorizing this, as it might come in handy for others…; in 2 flavours, one tut with the above folder reader php, and a 2nd for a db.  
when time…  
a quick try:

```php
<?
//give your connection an ID to close it later!
$link = mysql_connect("localhost","",""); 
mysql_select_db("aboy");

//build query
$query = "SELECT * FROM image";

//execute it with error suppression (@)
//(mysql error are not human-readable..)
$result = @mysql_query($query);

if(!$result) { //always good to check for errors!
    echo "&errorMsg = Query error, please try again";	
	//send your own clear message => textfield with var = errorMsg in flash to debug..
}    
// Find out how many pics/ result rows
$picCount = @mysql_num_rows($result);

$output = "";

//now loop
for ($count = 0; $count < $picCount; $count++) {
	$picture = mysql_fetch_array($result);
    // Extract picture details from database
    $output .= "&pic" . $count = urlencode(stripslashes($picture['pic']));
}

// Close link to database server!!
mysql_close($link);

?>

```

---

<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:** [August 28, 2003, 6:45am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/26 "2003-08-28T06:45:22Z")

</div>

its working finally!!!

Now I am scrolling through the database using (next) (Previous) buttons displaying text and an image from the rows in the database

I am using

load var = to load the pics

and

load variables = to load the text

they are having major conflicts with each other

the load variables cancel out the load vars

how do i use load vars and load variables together???

:rd: :block:

[Previous page](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703.md?page=1)
