PDA

View Full Version : php to listbox .... ?


bigsigh
04-10-2006, 06:46 PM
Hi, i hope this isnt to simple even for this section but i have tried all the tutorials on loops i could find and cannot achieve what i am aiming for.

the code i have so far is :

myData = new LoadVars();
myData.onLoad = function() {
enterdata();
};
myData.load("gallery.php");
enterdata = function () {
display.addItemAt(0, myData.username0);
display.addItemAt(1, myData.username1);
display.addItemAt(2, myData.username2);
};

it works 100% but i need it to work for any number of usernames that are returned not just for 0, 1, 2, .... etc as i define them.
I think i need a loop in the enterdata function , but im still very much a newbie so not sure if im right. :confused:

Any help would be very greatly appreciated .

Thanks

Simon

Xeef
04-10-2006, 07:16 PM
hi and welcome to As.Org

try :


enterdata = function () {
i = 0;
while (myData["username"+i] != undefined) {
display.addItemAt(i, myData["username"+i]);
i++;
}
};

bigsigh
04-10-2006, 07:27 PM
Fantastic thats exactly what i needed to do.
Iunderstand it now i see it , just couldnt get my head round it ,
Thanks alot , this is great :D

bigsigh
04-13-2006, 07:10 PM
The code below is a further development of the above,
It works to a point , the send and load is definately working as the trace (num) show the correct number of images stored by each user but i cannot get the second combo box to populate it just comes back with "undefined" repeated however many times NUM is .
Sorry if that isnt very clear, any help greatly appreciated as i am becoming a bit dispondant.


function getResults() {
testLVs = new LoadVars();
testLVs.username = selectValue;
testLVs.onLoad = function(success) {
if (success) {
trace("I have got "+testLVs.count+" results from the PHP script.");
var num:Number = testLVs.count;
trace (num);
i = 0;
while (i<num) {
this.display2.addItem (testLVs["pictures"+i]);
i++;
}
} else {
trace("You have problem now...");
}
};
testLVs.sendAndLoad("http://www.simonmcferran.co.uk/PHPcode/getimage.php", testLVs, "POST");
}

bigsigh
04-13-2006, 08:55 PM
Figured out it was the php file that was wrong in the end :mad: