maxx
10-31-2005, 05:56 PM
Hi all - it's been quite a while since I've had to deal with LoadVars, and I could've sworn I remembered basically what I was doing. I think I was wrong. So, I'm using a MySQL database, with PHP as the server side language. My php is very simple at this point -
$i=0;
$qry="SELECT id, name AS nm FROM tblphotogs;";
$rs=mysql_query($qry);
echo("&ctRws=".mysql_num_rows($rs));
while($line = mysql_fetch_assoc($rs)){
foreach($line as $key=>$var){
echo("&$key$i=$var");
}
$i++;
}
This returns the following when called on the php page itself...
&ctRws=3&id0=1&nm0=My Name&id1=2&nm1=Your Name&id2=3&nm2=Another Name
Which is how it should be. Now, I've got the following Actionscript...
var photoList:LoadVars = new LoadVars();
photoList.onLoad = function(success:Boolean):Void{
if(success){
var photogArr:Array = new Array();
var totRows:Number = Number(photoList.ctRws);
for(i=0; i<totRows; i++){
var crNm:String = "nm"+i;
var crID:String = "id"+i;
photogArr[i]['id'] = this[crID];
photogArr[i]['nm'] = this[crNm];
trace(photogArr[i]['id']+" - "+photogArr[i]['nm']);
}
}else{
debug.text = "There was an issue";
}
}
photoList.load("http://oldsys/csp/www/getPhotos.php");
This returns nothing but "undefined - undefined" 3 times over in my trace window.
:confused:
If I use the code
var testing:String = "nm"+1;
var q:String = this[testing];
trace(q);
instead of the for loop in the Actionscript, I can chage the "1" in line 1 for any of the three indexed returned values and it works correctly. I must be missing something very simple, because last time I dealt with this I was younger and dumber. At least I hope I was dumber then... Anybody see the problem with my code? Please?
$i=0;
$qry="SELECT id, name AS nm FROM tblphotogs;";
$rs=mysql_query($qry);
echo("&ctRws=".mysql_num_rows($rs));
while($line = mysql_fetch_assoc($rs)){
foreach($line as $key=>$var){
echo("&$key$i=$var");
}
$i++;
}
This returns the following when called on the php page itself...
&ctRws=3&id0=1&nm0=My Name&id1=2&nm1=Your Name&id2=3&nm2=Another Name
Which is how it should be. Now, I've got the following Actionscript...
var photoList:LoadVars = new LoadVars();
photoList.onLoad = function(success:Boolean):Void{
if(success){
var photogArr:Array = new Array();
var totRows:Number = Number(photoList.ctRws);
for(i=0; i<totRows; i++){
var crNm:String = "nm"+i;
var crID:String = "id"+i;
photogArr[i]['id'] = this[crID];
photogArr[i]['nm'] = this[crNm];
trace(photogArr[i]['id']+" - "+photogArr[i]['nm']);
}
}else{
debug.text = "There was an issue";
}
}
photoList.load("http://oldsys/csp/www/getPhotos.php");
This returns nothing but "undefined - undefined" 3 times over in my trace window.
:confused:
If I use the code
var testing:String = "nm"+1;
var q:String = this[testing];
trace(q);
instead of the for loop in the Actionscript, I can chage the "1" in line 1 for any of the three indexed returned values and it works correctly. I must be missing something very simple, because last time I dealt with this I was younger and dumber. At least I hope I was dumber then... Anybody see the problem with my code? Please?