1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: php & javascript Matrix

Discussion in 'Web Design & Development' started by jagonzalez, Mar 21, 2015.

Thread Status:
Not open for further replies.
Advertisement
  1. jagonzalez

    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
     
  2. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,386
    First Name:
    Jim
    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;)
     
  3. jagonzalez

    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
     
  4. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,386
    First Name:
    Jim
    Jag, for the benefit of present and future readers, would you show us the solution code please?
     
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 733,556 other people just like you!

Loading...
Similar Threads - Solved javascript Matrix
  1. Ravikumar112
    Replies:
    1
    Views:
    83
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1145190

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice