jjmusicpro Posted March 6, 2009 Share Posted March 6, 2009 I have a Loop that I am doing for records in a DB, and I needed to add them to an array, but can figure out how to get this structure down for this array... here is the array format... I know how to add an item to a single array like var mydata = ['data','data','data'], But dont know how to do these multi dimentional ones like this. var myData = [ ['3m Co',71.72,0.02,0.03,'9/1 12:00am'], ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'], ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'] ]; <javascript> <? DB CONNECTION.... LOOP if dbinfo = xx { add info to array } else { //dont add to array } END LOOP ?>.</javascript> Quote Link to comment https://forums.phpfreaks.com/topic/148196-loop-add-items-to-array/ Share on other sites More sharing options...
Floydian Posted March 6, 2009 Share Posted March 6, 2009 This is prolly the wrong forum for javascript help, but... Adding elements to a js array goes like this: myData[myData.length] = SOME_VALUE; The javascript forum: http://www.phpfreaks.com/forums/index.php/board,6.0.html Quote Link to comment https://forums.phpfreaks.com/topic/148196-loop-add-items-to-array/#findComment-777915 Share on other sites More sharing options...
jjmusicpro Posted March 6, 2009 Author Share Posted March 6, 2009 So that will format the array like the example is? I always used the push method, but it ended up maing the array like this ['','','',''] not like this[[],[],[],[],[],[]] Quote Link to comment https://forums.phpfreaks.com/topic/148196-loop-add-items-to-array/#findComment-778170 Share on other sites More sharing options...
KevinM1 Posted March 6, 2009 Share Posted March 6, 2009 So that will format the array like the example is? I always used the push method, but it ended up maing the array like this ['','','',''] not like this[[],[],[],[],[],[]] Regardless of whether you use push or the brackets, you need to put the new data into an array itself, then add that array as a new element of your main array. Quote Link to comment https://forums.phpfreaks.com/topic/148196-loop-add-items-to-array/#findComment-778176 Share on other sites More sharing options...
jjmusicpro Posted March 6, 2009 Author Share Posted March 6, 2009 So this is how i would do it? I would have 2 arrays, 1 that gets my data, then i add that data to the main array? arry1 = ['','','','','',''] Then I add array1 into array 2? Quote Link to comment https://forums.phpfreaks.com/topic/148196-loop-add-items-to-array/#findComment-778230 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.