Displaying Images In Flash From Mysql

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

use this:

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

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

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!!! :egg: --lol

wanna c???

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!!!

Ah, zam’, this code is terrible, lol :wink:
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:

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

?>

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: