3 Replies Latest reply on Mar 3, 2010 4:15 PM by pauland

    Simple Array Question


      I have a multidimensional array from a database query which provides the datasource for a datagrid. I want the user to be able to edit one of the columns in the datagrid and then update the database, no problem - this all works without issue.  My issue is that I have not been able to figure out how I can "restore defaults" for that edited column. Below is what I think should work, but does not.  I want to create myArray that I pass back to the database from the originalArray and the defaultArray in place of the edited column.


      var myArray:Array=new Array;

      //all the other arrays are declared - defaultArray holds the default values in column3, originalArray - only column1 is editable.


      for (i=0; i<20; i++) {

        myArray[i]=[ originalArray[i][0] , defaultArray[i][3] , originalArray[i][2]  ];



      As always thanks in advance for the time, it is appreciated.

        • 1. Re: Simple Array Question
          pauland Level 4

          Other considerations aside, you should write:


          for (i=0; i<20; i++) {

            myArray.push([ originalArray[i][0] ,  defaultArray[i][3] , originalArray[i][2]  ]);



          since the array is empty after you have declared it.



          • 2. Re: Simple Array Question
            EWN-CMI Level 1

            Thanks for the reply, are there other considerations?


            I can't remember if I tried the push seems like over the day I have tried it but may not in that syntax. I know I built 3 simple arrays and tried to push them into myArray, but I am sure it will come up again.  I decided that since I had to travel to the server anyway I'd just write a new specific function for just that column. Hate that - so I may back it out and try your advice.  I can restore my column now just passing the simple array with the default column to a new php function and that column is replicated in all my user editable tables so I may get lazy and say it's reusable enough.


            Thanks again for the help - marked as "Answered"  because it looks right.

            • 3. Re: Simple Array Question
              pauland Level 4

              " are there other considerations?"


              I just mean that my suggestion will populate the array according to the intentions of the code that you wrote, but it doesn't mean that it ultimately solves the problem!

              1 person found this helpful