# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![zammzamm](https://avatars.discourse-cdn.com/v4/letter/z/278dde/32.png) [@zammzamm](https://forum.kirupa.com/u/zammzamm)\
**Post date:** [July 15, 2003, 9:37pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/1 "2003-07-15T21:37:30Z")

</div>

OK Guys,

I am very very stuck  
:hair:

* * *

I have 10 placeholder movieclips for images inside of a main swf.

I need to load 10 images N2 these placeholders from a Mysql database.

Theres are also dynamic text fields that gives discriptions for each image.

The dynamic text is working fine.

Now the images are all in an . . . /image folder and the Mysql database has the filenames of each pic 1jpg, 2jpg, etc … . .

I need to know the specifically how to grab the images from the database so it will be consistant with the discription information coming out of the database through php.

I have over 500 rows in the database and each page displays 10 results. Also, I have the “previous/next” buttons to scroll through the database working

I need to know how to get those images into flash and correspond them with the description!!!

I need the php  
and the actionscript for the movieclips.

* * *

Ive been to phpforflash, flashkit, flashdb, macromedia, this site – everywhere, and I cant find it how to do this!!!

It’s been about 2 weeks trying to figure this out and I am going a little crazy!!!

by the way/ I think this is one of the best forums ive come across

I am new here and would like to park it for a while

😉

HELP!!!

mages into the placeholder movieclip in a ma:cyclops::cowboy:

---

<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 18, 2003, 8:08am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/2 "2003-07-18T08:08:55Z")

</div>

Is there anyone who can help me?

I am like banging my head up against the wall here!!

🙂

---

<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 18, 2003, 7:37pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/3 "2003-07-18T19:37:45Z")

</div>

Don’t bang, post your fla and php to see how you do this…where’s the pb, did you trace what ph sends you?..I don’t know how you set this up, so hard to help…  
And under what name did you post over at phpforflash? (if you did…)

---

<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 19, 2003, 4:46am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/4 "2003-07-19T04:46:21Z")

</div>

ok  
Actually its a simple question

How in the heck do you display images in a movieclip from a mysql database???

I dont understand the php  
or the actionscript

Im storing the name of the jpegs in the database.  
Im not storing the images directly into the database blobs

I can store and retreive text but not images. It’ weird!!!

Tried phpfored advanced cookbook - I still dont get it and I went over it like 10 times or so – lol

Am I am idiot or what – 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 19, 2003, 8:29am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/5 "2003-07-19T08:29:41Z")

</div>

Ah, ok, should’ve told me it’s the cookbook in the 1st place 🙂  
There’s osme errors in that code, did you check the support forums at phpforflash?  
Actually, make sure you’re using non-progressive jpg’s (look just the same, but progressive ones won’t load!), then try using a full url, as in h\*\*p://www.yoursitecom/images/whatever.jpg; loading them can be done in just one line:  
this.createEmptyMovieClip(“img\_mc”, 0).loadMovie(“my.jpg”);  
then go to [http://www.variablelimit.com](http://www.variablelimit.com) and check the example files from the book, there’s a working version there, test that & let me know…

**edit: jeremy removed his downloads, i’ll check my hd for you…**

---

<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 19, 2003, 8:42am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/6 "2003-07-19T08:42:03Z")

</div>

Ok, I have the files, but i need your mail, too large to attach here. PM-me.

---

<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 19, 2003, 12:37pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/7 "2003-07-19T12:37:36Z")

</div>

Wait!!! — lol

😉

I have the the new cookbook files and I love the program!!!

Actually, I would like to impliment some of the category/search features n2 my site.

Anyway, I just dont understand how the pictures are comming out of the database and loading into the flash movie.

I’ve studied the code for days and I just dont get it

What/how do I put in the actionscript ???  
What code do I use for php??

The cookbook ex is a little to advanced for me and he has alot of other dynamic information in his code. I cant tell what code is the picture load movie code vs. loading the other data.

I just need a simple run of the mill way to --well for now–

to load one pic into a movieclip from a database.

That would help me alot.

---

<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 19, 2003, 12:49pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/8 "2003-07-19T12:49:10Z")

</div>

ok, then in your db, for each pic, store in a field imgUrl the (full) path to the image.  
associated with the img’s id, you can easily get that…i hope, how much PHP =\> mySql do you know?  
So, in Flash, empty holder (or AS as per above with createEmpty…blabla). Button or whatever to click on =\> loadVariables(“imageGet.php?imgID=X”) , X being a number set with btn click  
then in PHP, connect to db, query: select \* from images where imgID=X  
from the result array, extract imgUrl and you’re set:  
$link="&imgUrl=yourlinkhere&";  
echo $link; (back to flash)  
in flash: loadMovie(imgUrl, target);  
…  
or, populate all the details dynamically, with a drop-down for example where the labels are the img name, and the data the url, then the changeHandler will use  
loadMovie([selected.getData()]); …something along those lines…  
just format the db-output you send to flash from php as you need it…  
are you following/able to code that (give it a-nother try…)  
lemme know…

---

<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 19, 2003, 1:21pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/9 "2003-07-19T13:21:34Z")

</div>

see next message

---

<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 19, 2003, 2:37pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/10 "2003-07-19T14:37:47Z")

</div>

[zammzammbamm@hotmail.com](mailto:zammzammbamm@hotmail.com)

This file might help in me understanding how to load pics from a database

## her is my php code

```
$query = "SELECT * FROM users";		

$result = @mysql_query($query);
$count = 0;
$output = "";

while ($row = mysql_fetch_array($result)) {

$Pix = stripslashes($row['Pixs']);		

```

$Cut = stripslashes($row[‘Cut’]);

```
$output .= "&pixs" . $count . "=" . urlencode($pixs);			
$output .= "&members" . $count . "=" . urlencode($members);			
$output .= "&location" . $count . "=" . urlencode($location);		
    $count++;
}

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

```

?\>

* * *

Now in my Mysql database I entered pics as 1.jpeg 2.jpeg etc . . .into a pics field  
How do I target my image folder???

* * *

## Here is the actionscript

stop ();

count = 0;

if (Number(records) == 0) {

```
disp_location1 = "";		
disp_members1 = "";
disp_Pixs1 = "";	

status = "No entries";

```

} else {

```
disp_location1 = this["location" add count];
disp_members1 = this["members" add count];
disp_Pixs1 = this["Pixs" add count];

status = "Entry " add (count+1) add " of " add Number(records);

```

}

count = 1;

if (Number(records) == 0) {

```
disp_location1 = "";		
disp_members1 = "";
disp_Pixs1 = "";	

status = "No entries";

```

} else {

```
disp_location2 = this["location" add count];
disp_members2 = this["members" add count];
disp_Pixs2 = this["Pixs" add count];
status = "Entry " add (count+1) add " of " add Number(records);

```

}

count = 2;

if (Number(records) == 0) {  
disp\_members2 = “”;  
disp\_location2 = “”;  
disp\_Pixs2 = “”;

```
status = "No entries in guestbook";

```

} else {  
// Display first record returned

```
disp_members = this["members" add count];
disp_location = this["location" add count];	
disp_Pixs3 = this["Pixs" add count];
status = "Entry " add (count+1) add " of " add Number(records);

```

}

etc . . . .

* * *

I would like the pixs to load on enter frame so where do I put this???

loadVariables(“imageGet.php?imgID=X”)

On the first frame?  
inside this actionscript??  
And . . .  
imgID-X —\> I am still unclear as to what X is

* * *

loadMovie(imgUrl, target);

what is the imgUrl???  
Is it the image name??  
Is it the path name to the image folder??

* * *

I am displaying 10 records from the database and to move through the database the user  
clicks on previous/next botton. So there are 10 images on each “flash page”

Also, I love your message board  
very creative!!!

I downloaded kingfishers board  
everything works but it doesnt display the correct number of tops  
When you insert a new topic it stays at “0 topic”

Anyway, here is my short version of the actionscript and the  
php file

---

<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 19, 2003, 3:18pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/11 "2003-07-19T15:18:14Z")

</div>

> X being a number set with btn click

Your PHP is very inconsistent…  
First you got  
$Pix = stripslashes($row[‘Pixs’]);  
then you use  
$output .= “&pixs” . $count . “=” . urlencode($pixs);  
but $Pix is not equal to $pixs !?  
(remeber, variable names in PHP are case sensitive, $pix != $Pix)  
You define $Cut, but don’t use it, you use $members and $ location but don’t define them…hmm…is that a copy of what you use?  
Also, in your query, there’s no LIMIT, whereas you say you display 10 records per page…?

In your AS, use a LOOP!!  
No need to write that many if’s: [AS] for (i=0; i \<Number(records); i++)…[/AS]

> I would like the pixs to load on enter frame so where do I put this???

…on enterFrame of what?

It’s all not so clear, if you send me the fla & php, i’ll fix it, got no time to make up an example, sorry.

It all depends on how you set up the fla, you can either set for example  
baseLoc=“[http://www.yoursite.com/images/](http://www.yoursite.com/images/)”  
and then just store the image name in the db as “1.jpg” etc,  
and loadMovie(baseLoc add imgUrl, target);

The kingfischer board has many bugs in the code… the new one (currently up on phpforflash) is also free now, get it from [www.dynamicflash.co.uk](http://www.dynamicflash.co.uk) (steve’s blog)

---

<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 20, 2003, 6:16pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/12 "2003-07-20T18:16:02Z")

</div>

ok here is the .fla. I also included the php and sql. It’s pretty big, sorry. Anyway, let me know.

Could someone do a tutorial on this issue, images, mysql and flash???

---

<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 23, 2003, 5:02am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/13 "2003-07-23T05:02:22Z")

</div>

Here is a tutorial from [actionscript-toolbox.com](http://actionscript-toolbox.com) which should hopefully end all your woes! The url is:

[http://www.actionscript-toolbox.com/samplemx\_loadjpg.php](http://www.actionscript-toolbox.com/samplemx_loadjpg.php)  
(or)  
[http://www.actionscript-toolbox.com/samplemx\_php.php](http://www.actionscript-toolbox.com/samplemx_php.php)

---

<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 23, 2003, 11:28am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/14 "2003-07-23T11:28:53Z")

</div>

Hay thax for the suggestion!!!

I’ve been through that script 100x’s and broke it apart  
to find just how and where the code is for the database-php-image thing.

I’ve had no luck with the tutorial at all!!!

It gets very confusing when she mixed the functions of the url buttons with the image code.

No luck with that tut

I’ve search all over the net and well  
it’s just not clicking with me

HELP!!!

---

<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 29, 2003, 9:55am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/15 "2003-07-29T09:55:44Z")

</div>

why isnt this working for me??

I have a movie with an empty MovieClip in Stage with instance name “target”. My database have a table named Images, with a column named pic.

In the database I have 1.jpg 2.jpg 3.jpg etc . . .

Actionscript

//Frame 1  
myData = new loadVars()  
myData.load(“getImage.php”)  
myData.onLoad = function(succes){  
if(succes){  
target.loadMovie(this.pic)  
} else trace(“error: couldn’t load from database”)  
}

PHP  
\<?php  
$Connect = mysql\_pconnect($hostname, $username, $password) or die(mysql\_error());  
mysql\_select\_db(“database”, $Connect);  
$result = mysql\_query(“select pic from Images LIMIT 1”); //just one image  
$image = mysql\_fetch\_array($result);  
echo “pic=$image[‘pic’]”;

whats wrong with 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:** [August 2, 2003, 2:11am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/16 "2003-08-02T02:11:30Z")

</div>

I have been trying to load a silly jpeg from a database n2 flash for a month now and nothing is working for me.

I’ve tried every flash forum, every php forum, every book and I still cannot get this thing to work.

can anyone help me or am i a ghost like my smilie???

---

<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 7, 2003, 10:06am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/17 "2003-08-07T10:06:39Z")

</div>

:run:

Here is my fla with included db

Help

SOS

:trout:

---

<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 11, 2003, 4:10pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/18 "2003-08-11T16:10:41Z")

</div>

OK

didnt get any help on the last zip file

here is a more simpler example

I can load an image into flash from php

but i cant seem to load it from mysql via php

here is a very very simple example as to what my code is

anyone help me please!!!

I am so darn close!! 👁

---

<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 11, 2003, 11:07pm UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/19 "2003-08-11T23:07:19Z")

</div>

ok.  
from your php:  
"…  
// Build and execute query  
$query = "SELECT \* FROM imagetable;  
=\>1/ you build, but you never excute the query!

$pic1 = “/images/pic”;  
$pic2 = “/images/pic”;  
$pic3 = “/images/pic”;  
$pic4 = “/images/pic”;  
$pic5 = “/images/pic”;  
=\>2/ you don’t use the query’s results to set up your output, you just set it yourself, what’s the whole db for then?

echo “&pic1=$pic&”;  
=\>3/ this should be “&pic1=”. $pic1; where $pic1 is one of the query’s results  
…"

here’s an example of how it should look:

```php
 // Build query to return catagory list...
$query = "SELECT * FROM forumCatagories ORDER BY displayOrder";

// Execute query
$result = @mysql_query($query);

if (!$result) {
    fail("Couldn't fetch catagory list");
}

// Fetch number of catagories
$catagoryCount = mysql_num_rows($result);

// For each catagory returned...
for ($count = 0; $count < $catagoryCount; $count++) {
    $catagory = mysql_fetch_array($result);

    // Output data
    print "&catagory" . $count . "ID=" . $catagory['catagoryID'];
    print "&catagory" . $count . "Title=" . urlencode($catagory['title']);
}

// Output catagory count...
print "&catagoryCount=$catagoryCount";

```

---

<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, 7:02am UTC](https://forum.kirupa.com/t/displaying-images-in-flash-from-mysql/25703/20 "2003-08-12T07:02:07Z")

</div>

Hay, thanx alot for your help!!!

Been trying to get code to work all day

still no luck

here is my new simple code

\<?PHP  
$Connect = mysql\_pconnect($localhost, “”, “”) or die(mysql\_error());  
mysql\_select\_db(“aboy”, $Connect);  
$result = mysql\_query(“select \* from image”);  
$image = mysql\_fetch\_array($result);  
echo “pic=”.$image[“pic”];  
//send it to flash  
?\>

in the database I have just 1 pic in database 1.jpg

database: aboy  
table: image  
field: pic

why isn’t this working???

and how do I call the image from the /image folder???

I AM SOOOOO CLOOOSSSEEEEEEEEEE :mario:

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