Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.