Groups | Blog | Home
all groups > flash data integration > july 2005 >

flash data integration : Flash Vs. MySql with PHP


MikeZfoundre
7/25/2005 11:07:35 PM
I have a php site with a MySql database on the backend. I want to use the
current database as is because the main site will still stay up. I want to
build a flash site that will do nothing more than read a few pieces of data
from the database.

In flash I want the dates section to show up, default to todays date and only
show dates from today forward for 2005 only and then a button to switch to 2006
and so on.

the database location, un, pw and such I have. The datbase entries I need to
call from are (in the order that they need to be sorted by as well)

eventDate
title
startTime
endTime

Now I want to display the dates in a reletively small area so they will need
to be scrollable. I have enough experience with PHP and Flash to take
directions but not enough to figure this out from scratch solo so any help
would be greatly appreciated. I can figure out how to fit it in my page and do
the fonts, colors, graphics, etc. I just need to be able to display the four
pieces of data from the DB that is already active.

Thank you so much in advance for your help.

LuigiL
7/26/2005 8:17:30 AM
A statement like this won't work in your php-file:
$qResult = mysql_query ("SELECT eventDate, title, startTime, endTime * FROM
nuke_4ncal ORDER BY eventDate ASC");
Either you select specified fields from the database (eventDate, title, etc..)
or * (ALL).
$qResult = mysql_query ("SELECT eventDate, title, startTime, endTime FROM
nuke_4ncal ORDER BY eventDate ASC");
or
$qResult = mysql_query ("SELECT * FROM nuke_4ncal ORDER BY eventDate ASC");

Do as much selecting as you can in PHP. You only want to show the upcoming
events starting with the current date? Make that selection in PHP which
prevents sending data you won't be using to Flash.

Once in Flash you use the LoadVars Class (since you are echoing a string with
variables from PHP). Because you want to display the data in a scrollable text
area, you would need to be able to loop over the results from the database. The
way you return the results is (according to your PHP-file) in the form:
&n=10&eventDate0=someDate&entry0=someText&

Once in Flash use a LoadVars object. The for loop will print all records with
line breaks.

var dataReceiver:LoadVars = new LoadVars();
dataReceiver.onLoad = function(){
// clean all previous text
myText_txt.text=""; // myText is a dynamic text field on the stage
for(var i=0; i<this.n; i++) {

myText_txt.text+=this["eventDate"+i]+newline+this["title"+i]+newline+this["start
Time"+i]+newline+this["endTime"+i]+newline+newline;
}
}

// Load the data
dataReceiver.load("urlToYourPHPfile");

One more error in your PHP-file:
$rString
..="&eventDate".$i."=".$row['eventDate']."&"."&entry".$i."=".$row['entry']."&";
You will get a string like
&n=10&eventDate0=someDate&&entry0=someText& and you have a double &&
Change that to
$rString
..="&eventDate".$i."=".$row['eventDate']."&entry".$i."=".$row['entry']."&";
and you only need the last & if you put your variables on seperate lines,
otherwise you can omit this.

No, it's not a complete answer but it will start you off. An excellent
resource for PHP-tutorials on dates (and a whole lot of other subjects) is
www.phpfreaks.com and in the data integration section of the MM site
(www.macromedia.com/devnet/mx/flash/data_integration_html) you will find
tutorials on what you are trying to achieve.

Hope this helps.
MikeZfoundre
7/26/2005 7:36:30 PM
That was amazing it is funny how the very subtle typos cause me so much grief!!

The PHP is turning up the results I am looking for now and I am using a flash
data grid to display. Is that where I will put the flash code?
MikeZfoundre
7/27/2005 12:00:00 AM
LuigiL
7/27/2005 7:32:45 AM
www.foundre.com/caltest2.php doesn't display any results from the database and
consequently nothing will show up in Flash. First get your PHP-script to work
properly.
If you want to display results in a datagrid then you need to set up a
dataprovider for the datagrid. You need to build an array from the variables
coming from PHP and then use the dataProvider property:
var resultsFromPHP:Array=[{eventDate:"someDate"}, {title:"Upcoming Flash
Show"}]; // and so on
dataGrid_dg.dataProvider=resultsFromPHP;
I've posted how to build an array from LoadVars-variables
http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=294&thre
adid=1027526&enterthread=y
AddThis Social Bookmark Button