Jump to content

Loop - Add Items to Array


jjmusicpro

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/148196-loop-add-items-to-array/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.