all groups > flash data integration > may 2006 >
You're in the

flash data integration

group:

PHP / MySQL / Flash 8



Re: PHP / MySQL / Flash 8 Motion Maker
5/1/2006 10:05:21 PM
flash data integration: Not enough detail to really figure out why.
Stabs in the dark:
NaN is most likely from an expression that has math operators and since you
are doing strings perhaps the +.

Display in the output window the expression you are using to assign to the
TextField.

Display in the output window the counter variable for any loop for the
above.


--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
I've created a simple MySQL Database, query via PHP and then load in the
vars
via LoadVars ( in Flash ). Everything seems ok.
But when I see the data in "myResult" textfield I get two extra slots of
info.
Has this ever happened to anyone before?

example:
John Doe : Something : Something Else
Mary Jane : Something : Something Else
Billy Foo : Something : Something Else
NaN : NaN : NaN
NaN : NaN : NaN

I get two extra rows with NaN.

Even the array.length includes these two rows, but when I do a test output
in
PHP I only see the three.
*pulling my hair out!*

Thanks in advance for anyones help. I know it has to be something simple.
It
always is...

PHP / MySQL / Flash 8 pwyon
5/2/2006 1:22:23 AM
I've created a simple MySQL Database, query via PHP and then load in the vars
via LoadVars ( in Flash ). Everything seems ok.
But when I see the data in "myResult" textfield I get two extra slots of info.
Has this ever happened to anyone before?

example:
John Doe : Something : Something Else
Mary Jane : Something : Something Else
Billy Foo : Something : Something Else
NaN : NaN : NaN
NaN : NaN : NaN

I get two extra rows with NaN.

Even the array.length includes these two rows, but when I do a test output in
PHP I only see the three.
*pulling my hair out!*

Thanks in advance for anyones help. I know it has to be something simple. It
always is...
Re: PHP / MySQL / Flash 8 pwyon
5/2/2006 5:26:34 AM
Here's some of my code. That parts I think may be causing the problem:



var dates:Array = new Array();
var events:Array = new Array();
var months:Array = new Array( "January" , "February" , "March" , "April" ,
"May" , "June" , "July" ,
"August" , "September" , "October" , "November" , "December" );

//...


var lv:LoadVars = new LoadVars();
lv.onLoad = function( success:Boolean ){
if( success ){
dates = this.TheDate.split( "|" );
events = this.TheEvent.split( "|" );
editResults( dates );
}else{
myResult = "Data not loaded."
}//end if
}//end onLoad
lv.load( "results.php" );


//...


function editResults( d:Array ){
//dates come in looking like this: yyyy-mm-dd
for( var i:Number=0 ; i<=d.length ; i++){
var year:Number = parseInt( dates[i].substring( 0 , 4 ) );
var month:Number = parseInt( dates[i].substring(5 , 7 ) );
var day:Number = parseInt( dates[i].substring(8 , 10 ) );
myResult += year +" /"+ months[month-1] +" /"+ day + " : "+ events[i] + "
"+ i + newline; //check out the results
}//end for
}//end function
Re: PHP / MySQL / Flash 8 Motion Maker
5/2/2006 7:48:45 PM
Looks like you have some errant data in this.TheDate creating additional
array position without the needed data for the editResults function.

The three trace statements I added below may help

var lv:LoadVars = new LoadVars();
lv.onLoad = function( success:Boolean ){
if( success ){
dates = this.TheDate.split( "|" );


trace( "lv:LoadVars - this.TheDate = [" + this.TheDate + "]");
trace( "lv:LoadVars - dates.length:" + dates.length);



events = this.TheEvent.split( "|" );
editResults( dates );
}else{
myResult = "Data not loaded."
}//end if
}//end onLoad
lv.load( "results.php" );


function editResults( d:Array ){
//dates come in looking like this: yyyy-mm-dd

trace("editResults - d.length:" + d.length);


for( var i:Number=0 ; i<=d.length ; i++){
var year:Number = parseInt( dates[i].substring( 0 , 4 ) );
var month:Number = parseInt( dates[i].substring(5 , 7 ) );
var day:Number = parseInt( dates[i].substring(8 , 10 ) );
myResult += year +" /"+ months[month-1] +" /"+ day + " : "+ events[i]
+ "
"+ i + newline; //check out the results
}//end for
}//end function

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
Here's some of my code. That parts I think may be causing the problem:



var dates:Array = new Array();
var events:Array = new Array();
var months:Array = new Array( "January" , "February" , "March" , "April" ,
"May" , "June" , "July" ,
"August" , "September" , "October" , "November" ,
"December" );

//...


var lv:LoadVars = new LoadVars();
lv.onLoad = function( success:Boolean ){
if( success ){
dates = this.TheDate.split( "|" );
events = this.TheEvent.split( "|" );
editResults( dates );
}else{
myResult = "Data not loaded."
}//end if
}//end onLoad
lv.load( "results.php" );


//...


function editResults( d:Array ){
//dates come in looking like this: yyyy-mm-dd
for( var i:Number=0 ; i<=d.length ; i++){
var year:Number = parseInt( dates[i].substring( 0 , 4 ) );
var month:Number = parseInt( dates[i].substring(5 , 7 ) );
var day:Number = parseInt( dates[i].substring(8 , 10 ) );
myResult += year +" /"+ months[month-1] +" /"+ day + " : "+ events[i]
+ "
"+ i + newline; //check out the results
}//end for
}//end function

Re: PHP / MySQL / Flash 8 Motion Maker
5/3/2006 12:28:04 AM
I missed that. Remember arrays are zero based and so you are counting from 0
to the length -1.
So you can do either <= array.length -1 or < array.length.



--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
Thanks for the input! I'll check out those results and see what's going on.
I'll post what I find out.

So far though, I simply changed " <= " to just " < ". That seemed to get
rid
of a lot of junk. Then I added " (d.length - 1 ) to get rid of the one left
over row.
Ugly--but, it worked.

So far so good now, but I still get some unpredictable results as I add
more
test data into the database.

Again, thank you very much for your time!

Re: PHP / MySQL / Flash 8 Motion Maker
5/3/2006 12:33:33 AM

The "|" is a separator, but on the last record you do not need to add it.
That is giving you one more item in the split on the Flash side.

You have two choices.
Either not place one more "|" on the last item in your PHP loop. That will
require an if statement that only adds the "|" if $i < $num_row.


Or you can remove one item from the Flash side after you split. You use
dates.pop()

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
Ok, I see 5 results from my "TheDate". But, the length in both "d.length"
and
"dates.length" are eq to 6.

What gives? Do you think it's my poor actionscripting or possibly something
to
do with my code in the "results.php". Take care and thanks for you help!

Here's the PHP code:


include "connect.php";


$query = "SELECT * FROM $table ORDER BY date";
$result = mysql_query( $query ) or die( "Could not select data from
table.") .
mysql_error( $conn );


$the_date = "";
$the_event = "";
$num_rows = mysql_num_rows( $result );


for( $i=0 ; $i<$num_rows ; $i++ ){//create an array for Flash
$the_date .= mysql_result( $result , $i , 'date' ) . "|";
$the_event .= mysql_result( $result , $i , 'event' ) . "|";
}//end while


echo ("&TheDate=" . $the_date . "&TheEvent=" . $the_event );


mysql_close( $conn );

Re: PHP / MySQL / Flash 8 pwyon
5/3/2006 1:45:39 AM
Thanks for the input! I'll check out those results and see what's going on.
I'll post what I find out.

So far though, I simply changed " <= " to just " < ". That seemed to get rid
of a lot of junk. Then I added " (d.length - 1 ) to get rid of the one left
over row.
Ugly--but, it worked.

So far so good now, but I still get some unpredictable results as I add more
test data into the database.

Again, thank you very much for your time!
Re: PHP / MySQL / Flash 8 pwyon
5/3/2006 2:19:24 AM
Ok, I see 5 results from my "TheDate". But, the length in both "d.length" and
"dates.length" are eq to 6.

What gives? Do you think it's my poor actionscripting or possibly something to
do with my code in the "results.php". Take care and thanks for you help!

Here's the PHP code:


include "connect.php";


$query = "SELECT * FROM $table ORDER BY date";
$result = mysql_query( $query ) or die( "Could not select data from table.") .
mysql_error( $conn );


$the_date = "";
$the_event = "";
$num_rows = mysql_num_rows( $result );


for( $i=0 ; $i<$num_rows ; $i++ ){//create an array for Flash
$the_date .= mysql_result( $result , $i , 'date' ) . "|";
$the_event .= mysql_result( $result , $i , 'event' ) . "|";
}//end while


echo ("&TheDate=" . $the_date . "&TheEvent=" . $the_event );


mysql_close( $conn );

Re: PHP / MySQL / Flash 8 Motion Maker
5/3/2006 1:39:43 PM
Super.

--=20
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
I touched up my PHP code, and used pop(). Everything seems to be =
working "ok"=20
for now. I still have some new errors in my recent code,=20
but I think it's more of an "Actionscript" topic than a "Data =
Integration"=20
one.

Re: PHP / MySQL / Flash 8 pwyon
5/3/2006 5:28:44 PM
I touched up my PHP code, and used pop(). Everything seems to be working "ok"
for now. I still have some new errors in my recent code,
but I think it's more of an "Actionscript" topic than a "Data Integration"
one.

Thanks once again for your help!
AddThis Social Bookmark Button