countdrac Posted November 21, 2007 Share Posted November 21, 2007 on a listbox change i need populate a new listbox getting info from a DB i can get all the info but im sitting with an array in my php form... can someone please explain what the best way to handle an array from the php and then put those into the new listbox... i was thinking i could just return (from php) one long string with a seperator (eg commas) - then i can get each one individually in the JS (when populating the listbox) but there must be an easier way? this is kinda what im having trouble with... while ($row = mysql_fetch_array($result)) { $list[$i][0] = $row['title']; $list[$i][1] = $row['file_name']; $i++; } mysql_close($connection); echo $listArray; //dont really know how to return this properly as an array So this is what i was doing before returning the array... should i keep this one and change the way php returns (string instead of array)? var response = xmlHttp.responseText; var plist = response.split(","); var pfile = ""; var length = plist.length; for (var i=0; i < length-1; i++) { var parshaEl = document.createElement('option'); //create option var El = document.getElementById('list'); El.appendChild(parshaEl); //then append it to the second dropdown list pfile = plist[i].split("##"); //when using the string the string was like title1##filename1,title2##filename2,... pfile[1]+=".inc"; parshaEl.value = pfile[1]; parshaEl.innerHTML = pfile[0]; thanks Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 21, 2007 Share Posted November 21, 2007 I used to serialize it using the php serialize function and unserialize it with a javascript unserialize function(this is not built in you'll have to download it from the net basically when you unserialize it, it will become a javascript array, you can check out more on serializing over here http://www.phpguru.org/static/PHP_Unserialize.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.