PDA

View Full Version : Showing mysql query results on flash


emilioestevezz
09-24-2004, 02:34 PM
Hi, i canīt find any tut for showing mysql query results on a flash movie, can anyone help me with this?


Thanks.
Emilio

happysmp
09-24-2004, 08:52 PM
Here you go!

http://webmonkey.wired.com/webmonkey/programming/php/tutorials/tutorial2.html

Digitalosophy
09-24-2004, 09:11 PM
or
http://www.flash-db.com/Tutorials/loading/index.php

:)

emilioestevezz
09-30-2004, 07:57 PM
or
http://www.flash-db.com/Tutorials/loading/index.php

:)

Ok!, thanks fot the tuts, now i have more idea how to do it, but im stilll having something wrong, i made this script and tested that php file is sending data, but i cant show it on the flash movie clip here is that script:


my_lv = new LoadVars()
my_lv.ref = this
my_lv.load("muestradevvars.php")
my_lv.onLoad = function(){
if(succes){
for(var i=0; i<this.cant; i++){
this.ref["apellido_tb"+i].text = this["apellido_tb"+i]
this.ref["nombre_tb"+i].text = this["nombre_tb"+i]
this.ref["telefono_tb"+i].loadMovie(this["telefono_tb"+i])
}
} else trace("Error loading data")
}

Is there anything wrong?
Why cant i see the query results? AAAHHH help????

Thanks

CyanBlue
09-30-2004, 10:56 PM
Howdy... :)

Normally 'this' within the onLoad handler means the LoadVars() object itself...
my_lv = new LoadVars();
my_lv.ref = this;
my_lv.load("muestradevvars.php");
my_lv.onLoad = function(success)
{
if (success)
{
for (var i = 0; i < this.cant; i++)
{
_level0.ref["apellido_tb" + i].text = this["apellido_tb" + i];
_level0.ref["nombre_tb" + i].text = this["nombre_tb" + i];
_level0.ref["telefono_tb" + i].loadMovie(this["telefono_tb" + i]);
}
}
else
{
trace("Error loading data");
}
};

emilioestevezz
10-01-2004, 02:57 PM
Howdy... :)

Normally 'this' within the onLoad handler means the LoadVars() object itself...
my_lv = new LoadVars();
my_lv.ref = this;
my_lv.load("muestradevvars.php");
my_lv.onLoad = function(success)
{
if (success)
{
for (var i = 0; i < this.cant; i++)
{
_level0.ref["apellido_tb" + i].text = this["apellido_tb" + i];
_level0.ref["nombre_tb" + i].text = this["nombre_tb" + i];
_level0.ref["telefono_tb" + i].loadMovie(this["telefono_tb" + i]);
}
}
else
{
trace("Error loading data");
}
};

Hi, thanks for your response.

Iīve changed the script for another:

if (datos_lv == undefined) {
datos_lv = new LoadVars();
// Use it to display the news
datos_lv.onLoad = function() {
var i=1;
ui.text_mc.text_tb.htmlText = "Clientes Agregados:";
// read as many date entries as there are in the file
while (this["apellido"+i] != undefined) {
ui.text_mc.text_tb.htmlText +=
"<b><font color='#184961'>" + this["apellido"+i] +
"</font></b><br>";
ui.text_mc.text_tb.htmlText +=
"<br>" + this["nombre"+i] + "<br><br>";
i++;
}
ui.text_mc.text_sb._visible = ui.text_mc.text_tb.htmlText.maxscroll > 1;
};
datos_lv.load("muestradevvars.php");
}

But still nothing! Itīs not showing me the data, iīve tested the muestradevvars on the browser and it shows the query result like expected, but for some reason flash itīs not loading and displaying it.

So i can say that the error must be on the script, what would you check on the entire movie clip? Im kinda newbie to flash so if you can explain to me like if you were expaining the procedure to a really stupid person i wouldnīt feel ofended :)

Thanks.
Emilio.

CyanBlue
10-01-2004, 03:25 PM
Heya... :)

Can you replace that routine with this code and tell me what you get???

datos_lv = new LoadVars();
datos_lv.onLoad = function(ok)
{
if (ok)
{
ui.text_mc.text_tb.htmlText = unescape(this);
}
else
{
ui.text_mc.text_tb.htmlText = "Problem";
}
};
datos_lv.load("muestradevvars.php");

And, please use PHP or AS tag to format your code for better readibility... :)

emilioestevezz
10-01-2004, 03:48 PM
Nothing happens. I mean it shows me the empty movie clip. :-(

#And, please use PHP or AS tag to format your code for better readibility...
How can i do this? Maybe editing it with dreamweaver?

Thanks



Heya... :)

And, please use PHP or AS tag to format your code for better readibility...
:)

CyanBlue
10-01-2004, 09:34 PM
Well... Let's do this... :)
Create a textField on the main timeline and give it an instance name of info_txt...

datos_lv = new LoadVars();
datos_lv.onLoad = function(ok)
{
if (ok)
{
_level0.info_txt.text = unescape(this);
}
else
{
_level0.info_txt.text = "Problem";
}
};
datos_lv.load("muestradevvars.php");

Tell me what you get... :)

As for the PHP/AS tag... You do this...
[ php]trace("hello");[ /php]
then you should see your code in the tag with some code coloring...
(You need to remove the space after [ though...)

[useastags]

roboter
10-02-2004, 12:27 AM
Hi,
i tried it its not working
i use an absolut url (using same location as swf - same result) on same domain as the swf.
Also FLASH MX 2.0
Also i tried doing the same and have still probs here is my code which noch works.

var myLoadVar = new LoadVars ();
myLoadVar.load("http://www.domain.de/x/y/some.php")
myLoadVar.onLoad = function (success){
if (success) {
stats.text=this.iplogger;
}
}


Any help or a link to a working exampel tutorial for Flash MX with AS 2.0 for loading php would be just great ;-)


cheers

CyanBlue
10-02-2004, 01:44 AM
Howdy and Welcome, roboter... :)

You could try this tutorial if you want to... It doesn't matter whether you use FMX or FMX 2004 or PHP or ASP... The concept is all the same...
http://tutorials.flashvacuum.com/article.php?article=1

What do you see if you type this in the IE??? Can you do the copy and paste so that I can see it???
http://www.domain.de/x/y/some.php

roboter
10-02-2004, 01:48 AM
I use firefox and all was working already with FLASH MX 1.0 now i changed to 2.0 and i feel i have to learn a complete new program :-)

Now i start to wonder if i must change the php also in order to make it run?

I checkin the tut u posted and its awesome .-) a good start for a flash based admin!

WOW - THX for th equick help and nice forum + support!

//LOADS EXTERNAL PHP DATA in FLASH MX 2.0!
statsData = new LoadVars();
statsData.onLoad = function (success)
{
if (success)
{
statsDisplay.text = unescape(this.iplogger);
}
}
statsData.load("iplog.php");




cheers

CyanBlue
10-02-2004, 01:53 AM
If your FMX/PHP combination was working fine, then probably there is nothing wrong with the PHP script... But, answer my previous question... What do you see??? :)

What's firefor???

roboter
10-02-2004, 02:07 AM
Yes its working and i meant firefox :)

And with the code above i see the stats now i tried to display all the time :)

And from your code i dont done this trace thingy just txt field and on and doesnt worked


cheers!

roboter
10-02-2004, 02:13 AM
the php output:
&iplogger=Hits: 1 - 1 today - 0 yesterday - last visit 03:06 - Your IP: 212.200.38.5 - 1 user online - 1 average per day

CyanBlue
10-02-2004, 02:32 AM
Uh... I thought that you said it is working... :confused:

Anyways... I don't see anything wrong in your PHP output... You might want to url encode those special characters such as : or space...

Then, the only thing that's left is to check if you have used proper syntax for FMX 2004... As you know already AS 2.0 is case sensitive language... Make sure that you are using the right syntac, and check out the data type and such AS 2.0 specific features... Or, publish your movie for AS 1.0/FP 6 to see if it works... :)

roboter
10-02-2004, 02:36 AM
Yes sorry for editing my olde rposting....

(all say with me...)


IT_IS_Finally_WORKING!im sooo0000oo happy thx!

..really!
your way of code did it and belive me i saw many code related this...actually i think this prob is very common and finally here is a sollution did i said im happy yet :9

Finally i can go back and do soem designworks :-)
I guess it has todo with the php string?
Cause i tried similar code and now with the unescape() Function which is completly new to me :) made it run!


cheers

roboter
10-03-2004, 08:32 PM
newsData = new LoadVars();
newsData.onLoad = function (success)
{
if (success)
{
newsDisplay.htmlText = unescape(this.news);
}
}
newsData.load("../myadmin/news.php");
stop();

am small update for loading php data as HTML.... atm the online tutorial example not working ("ERROR").
http://tutorials.flashvacuum.com/article.php?article=1

its like (seen at Macropmedia CSS handling (http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001764.html) )
this.createTextField("news_txt", 999, 10, 10, 320, 240);
news_txt.multiline = true;
news_txt.wordWrap = true;
news_txt.html = true;

var my_styleSheet:TextField.StyleSheet = new TextField.StyleSheet();
my_styleSheet.onLoad = function(success:Boolean) {
if (success) {
news_txt.styleSheet = my_styleSheet;
news_txt.htmlText = "<p class=\"heading\">Heading goes here!</p><p class=\"mainBody\">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>";
}
};
my_styleSheet.load("styles.css");

CyanBlue
10-03-2004, 09:15 PM
Looking good, roboter... :)

That tutorial page is pretty much like a ghost town... I am meaning to find another type of program that I can use, but I was too busy recently... :(
Thanks for the info and I'll see if I can knock it out... :)
(But then, it is Sunday today and I am still at work for the project... :()

roboter
10-04-2004, 12:33 AM
//Load var and add CSS
// Create a new style sheet and LoadVars object
var myVars:LoadVars = new LoadVars();
var styles = new TextField.StyleSheet();
// Location of CSS and text files to load
var txt_url = "../myadmin/news.php";
var css_url = "style.css";
// Load text to display and define onLoad handler
myVars.load(txt_url);
myVars.onData = function(content) {

story = content;
};
// Load CSS file and define onLoad handler:
styles.load(css_url);
styles.onLoad = function(ok) {
if (ok) {
newsDisplay.styleSheet = styles;
newsDisplay.htmlText = story ;
//ScrollBar.setScrollTarget(newsDisplay, true);

}
};
stop();

The code here is from the Macromedia technotes (http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001764.html) CSS related and this topic workarounds.
It works for output the news but not the CSS yet :/

I tried placing the CSS TAGS example:
//<p class='headline'>$myPhpContentVar

$newsString = "$newsString$dat$tit<br><br><p class=\"mainBody\">$pt</p><br><br>";
inside the news string, inside the news, and inside flash but either it doesnt displays the tag content .Btw this works great for images(mybeach.jpg inside news content). Also sometimes i get a "undiefiend error" then i change frame go back and it loads fine...?

Any ideas what i misstaken here? And where is the best place to add the css tags?

Btw check out http://mambo.mamboforge.net/demo/

CyanBlue
10-04-2004, 03:23 AM
Can't tell you anything about the CSS cuz I have never used in Flash before... :D

I've already checked out the Mambo and it looked like it's lacking the MODs since it is fairly new... I am thinking of PostNuke of phpNuke... There could be totally new alternative... I don't know... :)

roboter
10-04-2004, 05:55 AM
http://mamboforge.net/ atm their are 500 components for mambo :)
But choose what you like im new to mambo...

well and for the css i hope some1 else has some hint.

cheers

emilioestevezz
10-04-2004, 02:29 PM
Well... Let's do this... :)
Create a textField on the main timeline and give it an instance name of info_txt...

datos_lv = new LoadVars();
datos_lv.onLoad = function(ok)
{
if (ok)
{
_level0.info_txt.text = unescape(this);
}
else
{
_level0.info_txt.text = "Problem";
}
};
datos_lv.load("muestradevvars.php");

Tell me what you get... :)

As for the PHP/AS tag... You do this...
[ php]trace("hello");[ /php]
then you should see your code in the tag with some code coloring...
(You need to remove the space after [ though...)

These forums support automatic ActionScript code formatting and color-coding. Using this feature will assist people in reading and understanding your code and hopefully help you get better assistance. Best of all, it's easy to use; all you have to do is enter your code between a tag and a tag. For example, try
trace("This is a test");


Yeah!!! A big step to success, now i can see on the flash movie the output of muestradevvars.php, but i can see it on a really big font type, and all like:

&n=1&apellido0=Villegas&&nombre0=Sixto&&dni0=24.343.628&&telefono0=4234-5792&&dia0=&&mes0=&&aņo0=&&hora0=un&&minutos0=&&abogado0=Dra. Claudia I. Gorno&&asunto0=Malapraxis&&donde0=RadioDiez - Sensacion Termica&

So there is little things to learn, like formatting the data output, right?
Here is muestradevvares content for you to see, maybe there is something im forgetting:


$result = mysql_query("SELECT * FROM clientesnuevos");
if (!$result) {
echo("<P>Error realizando el query: " .
mysql_error() . "</P>");
exit();
}

$nRows = mysql_num_rows($result);
$rString ="&n=".$nRows;


for ($i=0; $i< $nRows; $i++){
$row = mysql_fetch_array($result);
$rString .="&apellido".$i."=".$row['apellidoclientesnuevos']."&"."&nombre".$i."=".$row['nombreclientesnuevos']."&"."&dni".$i."=".$row['dniclientesnuevos']."&"."&telefono".$i."=".$row['telefonoclientesnuevos']."&".
"&dia".$i."=".$row['diacitaclientesnuevos']."&"."&mes".$i."=".$row['mescitaclientesnuevos']."&"."&aņo".$i."=".$row['aņocitaclientesnuevos']."&"."&hora".$i."=".$row['horacitaclientesnuevos']."&"."&minutos".$i."=".$row['minutoscitaclientesnuevos']."&".
"&abogado".$i."=".$row['abogadoclientesnuevos']."&"."&asunto".$i."=".$row['asuntoclientesnuevos']."&"."&donde".$i."=".$row['dondeclientesnuevos']."&";
}
echo $rString."&";



Thanks cyan im back to life again.
Emilio

CyanBlue
10-04-2004, 03:18 PM
Thanks, roboter... I'll take another look on that site later...
As for the CSS... I think you have better luck if you post a new page with it... :)

emilioestevezz... You don't have to quote other people's post everytim you reply... That actually confuses people from time to time... Quote them only when it is necessary... :)
Hehe... I don't understand what your question is though... ;)

emilioestevezz
10-04-2004, 03:27 PM
Sorry about that Cyan ;-)

Well the thing is that now, with the code you posted before, now the movie is working, i mean i can see on the flash movie the mysql query results but i see that result on the movie in huge font size, what can be eg: arial 40.

And i see it encoded, this is what i see on the movie clip:


&n=1&apellido0=Villegas&&nombre0=Sixto&&dni0=24.343.628&&telefono0=4234-5792&&dia0=&&mes0=&&aņo0=&&hora0=un&&minutos0=&&abogado0=Dra. Claudia I. Gorno&&asunto0=Malapraxis&&donde0=RadioDiez - Sensacion Termica&


So, now it works, but i have to give some formatt to that output so employees can read it. And i would like to show it without the "&" and "=" so that the last thing to do? Got it?

Thanks.
Emilio

CyanBlue
10-04-2004, 03:32 PM
Oh... I guess that's something you have to browse around... I have not used CSS in Flash at all, so I wouldn't know... :)

As for the & and = signs... They are there to be parsed so that you can utilize the loaded data in Flash... If you do not need to parse them, then you'd need to fix the PHP script to do that...

emilioestevezz
10-04-2004, 03:47 PM
Ok, i would lurk the web for formatiing results, but as for the & = i do need to parse it like that so i can show it on the flash movie on a textbox, but do the have to be displayed on the movie?

CyanBlue
10-04-2004, 04:13 PM
Well... Tell you what... :)
Can you create a simple sample of what you are doing and upload it so that I can take a look??? Just copy your script and the textFields that need to display the data into the new file and include the CSS file so that I/somebody can take a look... :)

emilioestevezz
10-04-2004, 04:44 PM
Ok, ill try to explain what i want to do.

I have a php file called "muestradevvars.php" This file connects to a mysql server and make a simple query on a database called clients, and search for data stored on a table called "new clients" this is the PHP script of that file:


<?php
$connect = mysql_connect("localhost", "myuser", "youllnevergetme");
mysql_select_db("clientes", $connect);
$result = mysql_query("SELECT lastname, firstname, telephone FROM newclients");
$i = 0;
while($row=mysql_fetch_array($result)){
echo "lastname$i=$row[lastname]&firstname$i=$row[firstname]&telephone$i=$row[telephone]&";
$i++;
}
echo "i=$i";
?>


Then iīve tested this file, pointing my browser to it and its working as expected the output is:


&n=1&apellido0=Villegas&&nombre0=Sixto&&dni0=24.343.628&&telefono0=4234-5792&&dia0=&&mes0=&&aņo0=&&hora0=un&&minutos0=&&abogado0=Dra. Claudia I. Gorno&&asunto0=Malapraxis&&donde0=RadioDiez - Sensacion Termica&


And last: i want to show that query results on a flash movie, basically the flash movie is based on a kinda form image with ony one textfield, setted as dynamic data, html, multiline, and have "text_tb" as instance name.

So, this is the actionscript code that iīm using to show the php query result:


datos_lv = new LoadVars();
datos_lv.onLoad = function(ok)
{
if (ok)
{
_level0.text_tb.text = unescape(this);
}
else
{
_level0.text_tb.text = "Problem";
}
};
datos_lv.load("muestradevvars.php");


It all works like a charm, but when i get the flash movie tested on the server, i got the query result on it, but in very big font size and with the "&īs" and "0īs" , like this:


&n=1&apellido0=Villegas&&nombre0=Sixto&&dni0=24.343.628&&telefono0=4234-5792&&dia0=&&mes0=&&aņo0=&&hora0=un&&minutos0=&&abogado0=Dra. Claudia I. Gorno&&asunto0=Malapraxis&&donde0=RadioDiez - Sensacion Termica&

But on a very big font size like arial 40 so i cant really read the results.

Is there a way to formatt this output on the flash movie?

Thanks
Emilio