Solved: php & javascript Matrix

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

jagonzalez

Thread Starter
Joined
Aug 14, 2013
Messages
8
Hi, and thanks in advance for your help.

I have the following routine which works correclty if i run it. It defines the matrix "matriznomograma" and initializes it with the while, but only if I use a fixed value for the php array "arreglolaser" (in this case the number 1866)


Code:
               var matriznomograma = new Array (5000) 
               for (i = 0; i < 5000; i++)
               {
                    matriznomograma[i]=new Array(5);
               }
               var jj = 0;
               var ii = parseInt('<?php echo $i; ?>');

               while (jj <= ii) 
               { 
                 matriznomograma [jj][1] =                 '<?php echo $arreglolaser [1866][0]; ?>';
                 matriznomograma [jj][2] =                 '<?php echo $arreglolaser [1866][1]; ?>';
                 matriznomograma [jj][3] = parseFloat('<?php echo $arreglolaser [1866][2]; ?>');
                 matriznomograma [jj][4] = parseFloat('<?php echo $arreglolaser [1866][3]; ?>');
                 matriznomograma [jj][5] = parseFloat('<?php echo $arreglolaser [1866][4]; ?>');

                 jj=jj+1;
               }
If I want the matrix to varry with the value of the variable "jj", I substitute the variable jj instead of the number 1866 in the routine. But this routine doesn't work correctly.

Code:
              var matriznomograma = new Array (5000) 
               for (i = 0; i < 5000; i++)
               {
                    matriznomograma[i]=new Array(5);
               }
               var jj = 0;
               var ii = parseInt('<?php echo $i; ?>');

               while (jj <= ii) 
               { 
                 matriznomograma [jj][1] =                 '<?php echo $arreglolaser ['.jj.'][0]; ?>';
                 matriznomograma [jj][2] =                 '<?php echo $arreglolaser ['.jj.'][1]; ?>';
                 matriznomograma [jj][3] = parseFloat('<?php echo $arreglolaser ['.jj.'][2]; ?>');
                 matriznomograma [jj][4] = parseFloat('<?php echo $arreglolaser ['.jj.'][3]; ?>');
                 matriznomograma [jj][5] = parseFloat('<?php echo $arreglolaser ['.jj.'][4]; ?>');

                 jj=jj+1;
               }
How do I have to structure '<?php echo $arreglolaser ['.jj.'][0]; ?>' for it to work correctly?

Thanks again!

JAG
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
Hi JAG, I see you've discovered how to pass PHP variables into javascript, using echo(y)
However, if you want to access a php array you should probably go the JSON/Ajax route.
Here is a small tutorial, which I hope will help.
You may have to rethink your design in order to achieve desired results;)
 

jagonzalez

Thread Starter
Joined
Aug 14, 2013
Messages
8
Thanks you very much for your advice. I just added one line of code and it worked!

JAG
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
Jag, for the benefit of present and future readers, would you show us the solution code please?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top