PDA

View Full Version : Displaying Images In Flash From Mysql



zammzamm
July 15th, 2003, 05:37 PM
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:

zammzamm
July 18th, 2003, 04:08 AM
Is there anyone who can help me?

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



:)

eyezberg
July 18th, 2003, 03:37 PM
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..)

zammzamm
July 19th, 2003, 12:46 AM
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

eyezberg
July 19th, 2003, 04:29 AM
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 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..**

eyezberg
July 19th, 2003, 04:42 AM
Ok, I have the files, but i need your mail, too large to attach here. PM-me.

zammzamm
July 19th, 2003, 08:37 AM
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.

eyezberg
July 19th, 2003, 08:49 AM
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..

zammzamm
July 19th, 2003, 09:21 AM
see next message

zammzamm
July 19th, 2003, 10:37 AM
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

eyezberg
July 19th, 2003, 11:18 AM
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: for (i=0; i <Number(records); i++)..

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/"
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 (steve's blog)

zammzamm
July 20th, 2003, 02:16 PM
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???

javadi82
July 23rd, 2003, 01:02 AM
Here is a tutorial from actionscript-toolbox.com which should hopefully end all your woes! The url is:

http://www.actionscript-toolbox.com/samplemx_loadjpg.php
(or)
http://www.actionscript-toolbox.com/samplemx_php.php

zammzamm
July 23rd, 2003, 07:28 AM
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

zammzamm
July 29th, 2003, 05:55 AM
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??

zammzamm
August 1st, 2003, 10:11 PM
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????

zammzamm
August 7th, 2003, 06:06 AM
:run:

Here is my fla with included db

Help

SOS


:trout:

zammzamm
August 11th, 2003, 12:10 PM
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!! :eye:

eyezberg
August 11th, 2003, 07:07 PM
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:
// 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";

zammzamm
August 12th, 2003, 03:02 AM
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:

eyezberg
August 12th, 2003, 04:25 AM
zam' , do you realize this has been going on for a whole month now :) ?
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..?

zammzamm
August 12th, 2003, 04:33 AM
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

zammzamm
August 12th, 2003, 05:31 AM
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????

zammzamm
August 13th, 2003, 06:53 AM
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!!!!

eyezberg
August 13th, 2003, 08:10 AM
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:

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

?>

zammzamm
August 28th, 2003, 02:45 AM
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:

mjshirley79
May 19th, 2004, 02:54 PM
eyezberg,

Did you ever put together a tutorial on this...?

I use the directory reader and I see how it works, now on the flash end I'm looking to build a slideshow of sort.

just currious if you could point a semi-noob in the right direction?

Essentially something like this: http://www.productbeta.com/tutorials/show.php?goomba=3&

Except with out the ming junk...

or the same sort of look with the variables loaded from a database... (prefered)

AS examples greatfully welcomed! :-)

Yeldarb
May 19th, 2004, 05:36 PM
I just got finished doing something like this for a client, in a couple of weeks, when school is over, I will write a tutorial if i have time

lbeetles
May 19th, 2004, 08:14 PM
zammzamm would you be able to post your fla, so i could have a look at how you did this.

also did you get the updated fla's for the cookbook??? if so could u post them too as ive got the book but not the correct fla's.

mjshirley79
June 7th, 2004, 02:44 PM
Any luck building that tutorial? I'm desperate!:jail:

zammzamm
June 7th, 2004, 06:30 PM
i sent you something in your private message thingie


:cap:

zammzamm
June 7th, 2004, 06:37 PM
okay

this took me 3 months to get --- lol Im serious!!!!!!!
It is no where on the net!!!!!

here is the php code



<?php
// Attempt connection to MySQL server
$link = @mysql_connect("localhost","","");
if ($link == false) {
echo "&result=Fail&errormsg=";
echo urlencode("Failed to connect to MySQL server!");
echo "&";
exit;
}
// Attempt to select our DB
if (mysql_select_db("flash5dcs") == false) {
echo "&result=Fail&errormsg=";
echo urlencode("Error selecting database!\n");
echo urlencode("Error: " . mysql_error($link));
echo "&";
exit;
}
// Build and execute query
$query = "SELECT * FROM users";
$result = @mysql_query($query);
$count = 0;
$output = "";
while ($row = mysql_fetch_array($result)) {

$ScreenName = stripslashes($row['ScreenName']);
$MyEthnic = stripslashes($row['MyEthnic']);
$City = stripslashes($row['City']);
$Comments = stripslashes($row['Comments']);
$Posted = stripslashes($row['Posted']);
$Age = stripslashes($row['Age']);






$pic = stripslashes($row['pic']);
$pic1 = stripslashes($row['pic1']);
$pic2 = stripslashes($row['pic2']);
$pic3 = stripslashes($row['pic3']);
$pic4 = stripslashes($row['pic4']);
$pic5 = stripslashes($row['pic5']);
$pic6 = stripslashes($row['pic6']);
$pic7 = stripslashes($row['pic7']);
$pic8 = stripslashes($row['pic8']);
$pic9 = stripslashes($row['pic9']);
$pic10 = stripslashes($row['pic10']);








;
$output .= "&ScreenName" . $count . "=" . urlencode($ScreenName);
$output .= "&MyEthnic" . $count . "=" . urlencode($MyEthnic);
$output .= "&City" . $count . "=" . urlencode($City);
$output .= "&Comments" . $count . "=" . urlencode($Comments);
$output .= "&date" . $count . "=" . urlencode($Posted);
$output .= "&Age" . $count . "=" . urlencode($Age);

$output .= "&pic" . $count . "=" . urlencode($pic);
$output .= "&pic1" . $count . "=" . urlencode($pic1);
$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&";
?>
[PHP][HTML]

zammzamm
June 7th, 2004, 06:39 PM
put this on the timeline somewhere



function loadmember(index, slot) {

_root["disp_ScreenName"+slot] = myData["ScreenName"+index];
_root["disp_comments"+slot] = myData["comments"+index];
_root["disp_MyEthnic"+slot] = myData["MyEthnic"+index];
_root["disp_Age"+slot] = myData["Age"+index];
_root["disp_City"+slot] = myData["City"+index];

_root["pic"+slot].loadMovie("thumbnail/"+myData["pic"+index]);
}
myData = new LoadVars();
myData.load("abc.php");
myData.onLoad = function(success) {
if (success) {
loadmember(1,1);
loadmember(2,2);
loadmember(3,3);
loadmember(4,4);
loadmember(5,5);
loadmember(6,6);
loadmember(7,7);
loadmember(8,8);
loadmember(9,9);
loadmember(10,10);









} else {
statuswho="Error";
}
};

zammzamm
June 7th, 2004, 06:47 PM
now,

on the stage

do this

create a movieclip for the first pic and name it

pic1

in order to grab other information from the database in the same row you create your dynamic textboxes

disp_ScreenName1
disp_Comments1
disp_MyEthnic1 <------ don't ask??? :disco:
disp_Age1
disp_City1


you don't have to use disp_ . I used it for no apparent reason.

You will need to put these names in the vars thingie not the name of the instance!!!

ok u should now be able to bring up 1 row out of the database with a pic

to bring up a nother row with another pic with the corresponding info
do the same thing


create your empty movieclip and name it

pic2

create your dynamic textboxes

disp_ScreenName2
disp_Comments2
disp_MyEthnic2 <------ don't ask??? :disco:
disp_Age2
disp_City2


and do this 3-10 if you want to display 10 rows out of the database


:?)

lbeetles
June 7th, 2004, 06:48 PM
Zammzamm, Who To Check There Pm's???

zammzamm
June 7th, 2004, 06:51 PM
i decided to post the code

see the above stuff

:p:

zammzamm
June 7th, 2004, 06:55 PM
by the way

all thanx to eyezberg


I'm just the messenger!!!


He is King!!!!


:red:

lbeetles
June 7th, 2004, 07:32 PM
zammzamm, did you see this tut on the web, this maybe of some use for you to.
http://www.sephiroth.it/tutorials/flashPHP/catalog/

Do you have a working example online of what you have done???

mjshirley79
June 8th, 2004, 12:43 PM
Got the PM thanks, check yours... This is nice but far away from what I'm looking to accoplish...

mjshirley79
June 9th, 2004, 02:44 PM
This is what I'm using thus far, I finaly got it to load the second set of data, but only by calling the php file a second time...

Also I'm having to use multiple frames but I'd prefer to use AS to keep the file small and everything dynamic....

Any thoughts on how I might accoplish this... Using only one MC and one DynamicTextField, and AS to rename both on the loading of data?

OVER MY HEAD (-:




//Create LoadVars object and load file (use this each time I want new data)
myData = new LoadVars()
myData.load("select.php") //php line
myData.ref = this
//Fetch data
myData.onLoad = function(succes){
if(succes){
for(var i=0; i<this.cant; i++){
this.ref["Title_txt"+i].htmlText = "<b>"+this["Title"+i]+"</b>"
//this.ref["Comments_txt"+i].text = this["Comments"+i]
this.ref["holder_mc"+i].loadMovie(this["Image"+i])
}
} else trace("Error loading data")
}

//placed at the 3 frame to show data then go to load new data again
pauseDuration = 5*1000;
framesInLoop = 1;
if (startTime == null) {
startTime = getTimer();
gotoAndPlay(_currentframe-framesInLoop);
} else {
lapsedTime = getTimer()-startTime;
if (lapsedTime<pauseDuration) {
gotoAndPlay(_currentframe-framesInLoop);
} else {
startTime = null;
this.fade.play();
this.purchaseProcess.play();
}
}




<?php

$connect = mysql_connect("localhost", "***", "***");

mysql_select_db("anastasio", $connect);

$result = mysql_query("SELECT Title, Image FROM titles");

$cant = 0;

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

echo "Title$cant=$row[Title]&Image$cant=$row[Image]&";

$cant++;

}

echo "cant=$cant";

?>

mjshirley79
June 9th, 2004, 02:46 PM
www.rjbagan.com/test/a/loadDB.zip (http://www.rjbagan.com/test/a/loadDB.zip)

zammzamm
June 9th, 2004, 03:12 PM
try this


//number of images
imgCount=19;

//create a MC to hold your images
this.createEmptyMovieClip("pic");

//set up a timer that calls you function
//1000 milliseconds = aprox 1 sec
animIntreval=setInterval(swapImg,1000);

//the function called every 2 seconds
function swapImg(){
loadMovie("img" + Math.ceil(Math.random()*imgCount)+".jpg","pic");}




I would suggest instead of using a database just grab the images from a directory and go into photoshop, fireworks, or flash even and put the titles on the images.


:mario:

mjshirley79
June 9th, 2004, 04:27 PM
One thing... I want to make the number of pics and open variable...? I don't want to give it a limit... Then check the number of images in the DB... That would work right... I have no clue on it, but just for Devils Advicate...

BTW: Using a DB cause the images & text will be used all over the site in different ways... Not only that but on an upcomming use of this I'll be posting approx. 500 images a day!

zammzamm
June 11th, 2004, 09:58 AM
put this in your action script

empty movieclip is called pic1
put all of your pics in a folder and name the folder picfolder
dynamic text "variable" name is Text1
the php file is called abcchoose.php

you can change any of the names if you like
----------------------------------------------------------






function loadmember(index, slot) {
_root["Text"+slot] = myData["Text"+index];
_root["pic"+slot].loadMovie("picfolder/"+myData["pic1"+index]);
}
var numer2:Number = 0;
myData = new LoadVars();
myData.load("abcchoose.php");
myData.onLoad = function(success) {
if (success) {
loadmember(0, 1);
animIntreval = setInterval(swapImg, 8000);
} else {
statuswho = "Error";
}
};
//the function called every 2 seconds
function swapImg() {

_root["numer2"] = _root["numer2"]+1;
if (_root["numer2"]>=myData["records"]) {
_root["numer2"] = 0;
}
loadmember(_root["numer2"], 1);
}





:p:

OKAY I FIXED IT HERE TOO!!!!


:ch: :gm: :pir:

zammzamm
June 11th, 2004, 10:03 AM
<?php
// Attempt connection to MySQL server
$link = @mysql_connect("localhost","","");
if ($link == false) {
echo "&result=Fail&errormsg=";
echo urlencode("Failed to connect to MySQL server!");
echo "&";
exit;
}
// Attempt to select our DB
if (mysql_select_db("yourdatabasenamegoeshere") == false) {
echo "&result=Fail&errormsg=";
echo urlencode("Error selecting database!\n");
echo urlencode("Error: " . mysql_error($link));
echo "&";
exit;
}
// Build and execute query
$query = "SELECT * FROM users ORDER BY RAND()";
$result = @mysql_query($query);
$count = 0;
$output = "";
while ($row = mysql_fetch_array($result)) {

$Text = stripslashes($row['Text']);
$pic1 = stripslashes($row['pic1']);
;


$output .= "&Text" . $count . "=" . urlencode($Text);
$output .= "&pic1" . $count . "=" . urlencode($pic1);
$output .= "&id" . $count . "=" . urlencode($count);



$count++;
}
echo $output . "&records=" . $count . "&result=Okay&";
?>

:cop:
:asian:
:flower:
:kir:

mjshirley79
June 14th, 2004, 09:21 AM
**Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 18: Syntax error.
Math.floor(Math.random()*myData["records"]), 1);
Total ActionScript Errors: 1 Reported Errors: 1

zammzamm
June 14th, 2004, 10:17 AM
Don't know how that got in there
try this
Just delete it!!!







function swapImg() {

_root["numer2"] = _root["numer2"]+1;
if (_root["numer2"]>=myData["records"]) {
_root["numer2"] = 0;
}
loadmember(_root["numer2"], 1);
}





:tie:

mjshirley79
June 14th, 2004, 12:05 PM
I think we're real close on this... But with what I have in the DB and swf this is what I get... image, nothing loads... and text, undefined...

+----+------------+----------+
| ID | Text | pic1 |
+----+------------+----------+
| 1 | Anastasio | pic1.jpg |
| 2 | In the car | pic2.jpg |
+----+------------+----------+

This is right?

zammzamm
June 14th, 2004, 02:31 PM
type in www.yoursite/abcchoose.php

and tell me what you get


also

did you put the pics in a folder?

and make sure your table name is users

use small caps for the column "id" in the database

:rd:

mjshirley79
June 14th, 2004, 02:38 PM
Just incase, I'm zipping what I have and posting it here...

http://www.rjbagan.com/load.zip


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /test/loadimages/abcchoose.php on line 23
&records=0&result=Okay& Hope I'm not getting things all backwards now!:huh:


function loadmember(index, slot) {
_root["Text"+slot] = myData["Text"+index];
_root["pic"+slot].loadMovie("picfolder/"+myData["pic1"+index]);
}
var numer2:Number = 0;
myData = new LoadVars();
myData.load("abcchoose.php");
myData.onLoad = function(success) {
if (success) {
loadmember(0, 1);
animIntreval = setInterval(swapImg, 8000);
} else {
statuswho = "Error";
}
};
//the function called every 2 seconds
function swapImg() {
Math.floor(Math.random()*myData["records"]), 1);
_root["numer2"] = _root["numer2"]+1;
if (_root["numer2"]>=myData["records"]) {
_root["numer2"] = 0;
loadmember(_root["numer2"], 1);
}




<?php
// Attempt connection to MySQL server
$link = @mysql_connect("localhost","***","***");
if ($link == false) {
echo "&result=Fail&errormsg=";
echo urlencode("Failed to connect to MySQL server!");
echo "&";
exit;
}
// Attempt to select our DB
if (mysql_select_db("anastasio") == false) {
echo "&result=Fail&errormsg=";
echo urlencode("Error selecting database!\n");
echo urlencode("Error: " . mysql_error($link));
echo "&";
exit;
}
// Build and execute query
$query = "SELECT * FROM titles ORDER BY RAND()";
$result = @mysql_query($query);
$count = 0;
$output = "";
while ($row = mysql_fetch_array($result)) {
$Text1 = stripslashes($row['Text']);
$pic1 = stripslashes($row['pic1']);
;
$output .= "&Text" . $count . "=" . urlencode($Text1);
$output .= "&pic1" . $count . "=" . urlencode($pic1);
$output .= "&id" . $count . "=" . urlencode($count);
$count++;
}
echo $output . "&records=" . $count . "&result=Okay&";
?>

mjshirley79
June 14th, 2004, 02:43 PM
FYI:

DB name: anastasio
Table: titles

zammzamm
June 14th, 2004, 03:16 PM
i named your empty movie clip pic1

and there was some freaky actionscript thingie happening

:hugegrin:

try this

i didn't check the php code
it should be fine

:hugegrin:

mjshirley79
June 14th, 2004, 03:21 PM
??? What ???

No link, no attachment?



try this

zammzamm
June 14th, 2004, 03:26 PM
check your private email

mjshirley79
June 14th, 2004, 04:35 PM
Wahoo, this works great now!

lol, one thing... How do I get the images to not cache? I changed the images (not the names) and I still get the old images... Even after clearing my cache and changing the jpegs, and sf on the server...?

zammzamm
June 15th, 2004, 02:55 AM
It is not cacheing the images.

After you upload your 500 pics or so to the database it will display random pics .

:pir:

mjshirley79
June 15th, 2004, 08:42 AM
Actually it was the still proxy server cacheing the jpg... Forgot all about that booger while I was testing...



It is not cacheing the images.

After you upload your 500 pics or so to the database it will display random pics .

:pir:

mjshirley79
June 15th, 2004, 11:11 AM
One other thing came up as a question to me from a friend... Maybe there is a simple way to do this... load the image folder path, picfolder in the past example, from the database...

Then the only editing would be to the database & the php files once... and the swf could be put in any folder, no editing needed! C:-) ???