Loading ...
Sorry, an error occurred while loading the content.

RE: [php-objects] convert a multidimensional array to javascript

Expand Messages
  • Wolf Zscheile
    Hi Robert, this looks pretty good to me, but I m still struggling to digest and get used of it.. It might take a little time and I will probably come back
    Message 1 of 16 , Feb 1, 2007
    • 0 Attachment
      Hi Robert,

      this looks pretty good to me, but I'm still struggling to 'digest' and
      'get used' of it..

      It might take a little time and I will probably come back with a few
      more questions..

      Thanks a lot for your time and effort !!

      Greetings from Goodwater, AL,

      Wolf



      -----Original Message-----
      From: php-objects@yahoogroups.com [mailto:php-objects@yahoogroups.com] On
      Behalf Of Atkinson, Robert
      Sent: Wednesday, January 31, 2007 3:16 AM
      To: php-objects@yahoogroups.com
      Subject: RE: [php-objects] convert a multidimensional array to javascript



      Wolf, based on what you've said, this is the code to convert a PHP array
      into
      a JavaScript array :-

      <?php

      // Define a PHP array
      $arySound[0]-["name"] = "Sound1";
      $arySound[0]-["val1"] = "Sound1_val_-1";
      $arySound[0]-["val2"] = "Sound1_val_-2";
      $arySound[0]-["val3"] = "Sound1_val_-3";

      $arySound[1]-["name"] = "Sound2";
      $arySound[1]-["val1"] = "Sound2_val_-1";
      $arySound[1]-["val2"] = "Sound2_val_-2";
      $arySound[1]-["val3"] = "Sound2_val_-3";

      $topi = 0; // This is the top level count
      $subi = 0; // This is the sub-level count

      echo "<script>\n"-;
      echo "var myArray = new Array();\n"; // Define an initital array called
      'myArray'

      foreach ($arySound as $subArray) {
      echo "myArray[$topi] = new Array();\n"; // Step through each
      top level

      foreach ($subArray as $key=>$value) { // Step through each
      sub-level
      echo "myArray[$topi]-[$subi] = '$value';\n"-;
      $subi++; // Increment the sub-level count to create the next
      array entry
      }

      $topi++; // Increment the top level count, to create a new
      sub-array
      }

      echo "</script>\n"-;

      ?>

      This should output the JavaScript :-

      <script>
      var myArray = new Array();
      myArray[0] = new Array();
      myArray[0][0] = 'Sound1';
      myArray[0][1] = 'Sound1_val_-1';
      myArray[0][2] = 'Sound1_val_-2';
      myArray[0][3] = 'Sound1_val_-3';
      myArray[1] = new Array();
      myArray[1][4] = 'Sound2';
      myArray[1][5] = 'Sound2_val_-1';
      myArray[1][6] = 'Sound2_val_-2';
      myArray[1][7] = 'Sound2_val_-3';
      </script>

      Rob.


      -----Original Message-----
      From: HYPERLINK
      "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
      [mailto:HYPERLINK
      "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com] On
      Behalf Of Wolf Zscheile
      Sent: 30 January 2007 23:15
      To: HYPERLINK
      "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
      Subject: RE: [php-objects] convert a multidimensional array to javascript

      Hi Jaldip and Rob,

      thanks a lot for offering your help !!

      Ok..

      I try to built a php/Mysql database for our english-speaking friends to
      learn
      and hear the German language:
      HYPERLINK
      "HYPERLINK
      "http://www.saxonyroots.com/Nightschool/"http://www.saxonyro-ots.com/Nightsc
      h-ool/"HYPERLINK
      "http://www.saxonyroots.com/Nightsch"http://www.saxonyro-ots.com/Nightsch
      ool/

      The data is supposed to be loaded into a php array like:
      $sound=array(-sound1(array(-s1,s2,s3,-etc)
      (sound2(array(-s1,s2,s3,-etc)

      this array should then go to Javascript where I could ask sound [1][2] =
      what..
      There is so much talk about JSON.. AJAX.. etc.. which is quite confusing to
      a
      Newbe..

      Thanks you very much for your help.
      Wolf




      -----Original Message-----
      From: HYPERLINK
      "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
      [mailto:HYPERLINK
      "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com] On
      Behalf Of Jaldip Upadhyay
      Sent: Monday, January 29, 2007 9:59 PM
      To: HYPERLINK
      "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
      Subject: Re: [php-objects] convert a multidimensional array to javascript

      Hi,
      Give me better definition so that it would be better for me to understand
      your problem.Right now it seems like AJAX will be the solutionfor you.

      Regards
      Jaldip Upadhyay
      91-9427287333

      Wolf Zscheile <HYPERLINK
      "mailto:saxonyroots-%40charter.-net"saxonyroots@--charter.-net> wrote: Hi
      All,

      what is the best way to convert a multidimensional PHP array to javascript
      ??

      Thanks for any help,

      Wolf

      --
      No virus found in this outgoing message.
      Checked by AVG Free Edition.
      Version: 7.5.432 / Virus Database: 268.17.12/653 - Release Date: 1/26/2007
      11:11 AM

      [Non-text portions of this message have been removed]

      ---------------------------------------
      Here's a new way to find what you're looking for - Yahoo! Answers

      [Non-text portions of this message have been removed]

      --
      No virus found in this incoming message.
      Checked by AVG Free Edition.
      Version: 7.5.432 / Virus Database: 268.17.14/657 - Release Date: 1/29/2007
      9:04 AM

      --
      No virus found in this outgoing message.
      Checked by AVG Free Edition.
      Version: 7.5.432 / Virus Database: 268.17.15/659 - Release Date: 1/30/2007
      9:31 AM


      [Non-text portions of this message have been removed]

      PHP Data object relational mapping generator
      HYPERLINK "http://www.metastorage.net/"http://www.metastor-age.net/
      Yahoo! Groups Links

      ************-*********-*********-*********-*********-*********-*********-***
      ******-********
      Any opinions expressed in email are those of the individual and not
      necessarily those of the company. This email and any files transmitted with
      it are confidential and solely for the use of the intended recipient
      or entity to who they are addressed. It may contain material protected by
      attorney-client privilege. If you are not the intended recipient, or a
      person responsible for delivering to the intended recipient, be advised that
      you have received this email in error and that any use is strictly
      prohibited.

      Random House Group + 44 (0) 20 7840 8400
      HYPERLINK "http://www.randomhouse.co.uk"http://www.randomho-use.co.uk
      HYPERLINK
      "http://www.booksattransworld.co.uk"http://www.booksatt-ransworld.-co.uk
      HYPERLINK
      "http://www.kidsatrandomhouse.co.uk"http://www.kidsatra-ndomhouse.-co.uk
      Generic email address - HYPERLINK
      "mailto:enquiries%40randomhouse.co.uk"enquiries@...

      Name & Registered Office:
      THE RANDOM HOUSE GROUP LIMITED
      20 VAUXHALL BRIDGE ROAD
      LONDON
      SW1V 2SA
      Random House Group Ltd is registered in the United Kingdom with company No.
      00954009, VAT number 102838980
      ************-*********-*********-*********-*********-*********-*********-***
      ******-********






      --
      No virus found in this incoming message.
      Checked by AVG Free Edition.
      Version: 7.5.432 / Virus Database: 268.17.15/659 - Release Date: 1/30/2007
      9:31 AM



      --
      No virus found in this outgoing message.
      Checked by AVG Free Edition.
      Version: 7.5.432 / Virus Database: 268.17.17/661 - Release Date: 1/30/2007
      11:30 PM



      [Non-text portions of this message have been removed]
    • Wolf Zscheile
      Hi Rob., still got problems... Your code looks ok, but the output is in a bunch , how can I get the output for each individual item ? With Javascript I need
      Message 2 of 16 , Feb 1, 2007
      • 0 Attachment
        Hi Rob.,

        still got problems...

        Your code looks ok, but the output is in a 'bunch', how can I get the output
        for
        each individual item ?

        With Javascript I need
        var soundx= myArray[0][3];

        and to process this further

        soundManager.play('soundx');

        Please excuse the stupid questions of a Newbe..

        Greeting,

        Wolf




        -----Original Message-----
        From: php-objects@yahoogroups.com [mailto:php-objects@yahoogroups.com] On
        Behalf Of Atkinson, Robert
        Sent: Wednesday, January 31, 2007 3:16 AM
        To: php-objects@yahoogroups.com
        Subject: RE: [php-objects] convert a multidimensional array to javascript



        Wolf, based on what you've said, this is the code to convert a PHP array
        into
        a JavaScript array :-

        <?php

        // Define a PHP array
        $arySound[0]-["name"] = "Sound1";
        $arySound[0]-["val1"] = "Sound1_val_-1";
        $arySound[0]-["val2"] = "Sound1_val_-2";
        $arySound[0]-["val3"] = "Sound1_val_-3";

        $arySound[1]-["name"] = "Sound2";
        $arySound[1]-["val1"] = "Sound2_val_-1";
        $arySound[1]-["val2"] = "Sound2_val_-2";
        $arySound[1]-["val3"] = "Sound2_val_-3";

        $topi = 0; // This is the top level count
        $subi = 0; // This is the sub-level count

        echo "<script>\n"-;
        echo "var myArray = new Array();\n"; // Define an initital array called
        'myArray'

        foreach ($arySound as $subArray) {
        echo "myArray[$topi] = new Array();\n"; // Step through each
        top level

        foreach ($subArray as $key=>$value) { // Step through each
        sub-level
        echo "myArray[$topi]-[$subi] = '$value';\n"-;
        $subi++; // Increment the sub-level count to create the next
        array entry
        }

        $topi++; // Increment the top level count, to create a new
        sub-array
        }

        echo "</script>\n"-;

        ?>

        This should output the JavaScript :-

        <script>
        var myArray = new Array();
        myArray[0] = new Array();
        myArray[0][0] = 'Sound1';
        myArray[0][1] = 'Sound1_val_-1';
        myArray[0][2] = 'Sound1_val_-2';
        myArray[0][3] = 'Sound1_val_-3';
        myArray[1] = new Array();
        myArray[1][4] = 'Sound2';
        myArray[1][5] = 'Sound2_val_-1';
        myArray[1][6] = 'Sound2_val_-2';
        myArray[1][7] = 'Sound2_val_-3';
        </script>

        Rob.


        -----Original Message-----
        From: HYPERLINK
        "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
        [mailto:HYPERLINK
        "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com] On
        Behalf Of Wolf Zscheile
        Sent: 30 January 2007 23:15
        To: HYPERLINK
        "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
        Subject: RE: [php-objects] convert a multidimensional array to javascript

        Hi Jaldip and Rob,

        thanks a lot for offering your help !!

        Ok..

        I try to built a php/Mysql database for our english-speaking friends to
        learn
        and hear the German language:
        HYPERLINK
        "HYPERLINK
        "http://www.saxonyroots.com/Nightschool/"http://www.saxonyro-ots.com/Nightsc
        h-ool/"HYPERLINK
        "http://www.saxonyroots.com/Nightsch"http://www.saxonyro-ots.com/Nightsch
        ool/

        The data is supposed to be loaded into a php array like:
        $sound=array(-sound1(array(-s1,s2,s3,-etc)
        (sound2(array(-s1,s2,s3,-etc)

        this array should then go to Javascript where I could ask sound [1][2] =
        what..
        There is so much talk about JSON.. AJAX.. etc.. which is quite confusing to
        a
        Newbe..

        Thanks you very much for your help.
        Wolf




        -----Original Message-----
        From: HYPERLINK
        "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
        [mailto:HYPERLINK
        "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com] On
        Behalf Of Jaldip Upadhyay
        Sent: Monday, January 29, 2007 9:59 PM
        To: HYPERLINK
        "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
        Subject: Re: [php-objects] convert a multidimensional array to javascript

        Hi,
        Give me better definition so that it would be better for me to understand
        your problem.Right now it seems like AJAX will be the solutionfor you.

        Regards
        Jaldip Upadhyay
        91-9427287333

        Wolf Zscheile <HYPERLINK
        "mailto:saxonyroots-%40charter.-net"saxonyroots@--charter.-net> wrote: Hi
        All,

        what is the best way to convert a multidimensional PHP array to javascript
        ??

        Thanks for any help,

        Wolf

        --
        No virus found in this outgoing message.
        Checked by AVG Free Edition.
        Version: 7.5.432 / Virus Database: 268.17.12/653 - Release Date: 1/26/2007
        11:11 AM

        [Non-text portions of this message have been removed]

        ---------------------------------------
        Here's a new way to find what you're looking for - Yahoo! Answers

        [Non-text portions of this message have been removed]

        --
        No virus found in this incoming message.
        Checked by AVG Free Edition.
        Version: 7.5.432 / Virus Database: 268.17.14/657 - Release Date: 1/29/2007
        9:04 AM

        --
        No virus found in this outgoing message.
        Checked by AVG Free Edition.
        Version: 7.5.432 / Virus Database: 268.17.15/659 - Release Date: 1/30/2007
        9:31 AM


        [Non-text portions of this message have been removed]

        PHP Data object relational mapping generator
        HYPERLINK "http://www.metastorage.net/"http://www.metastor-age.net/
        Yahoo! Groups Links

        ************-*********-*********-*********-*********-*********-*********-***
        ******-********
        Any opinions expressed in email are those of the individual and not
        necessarily those of the company. This email and any files transmitted with
        it are confidential and solely for the use of the intended recipient
        or entity to who they are addressed. It may contain material protected by
        attorney-client privilege. If you are not the intended recipient, or a
        person responsible for delivering to the intended recipient, be advised that
        you have received this email in error and that any use is strictly
        prohibited.

        Random House Group + 44 (0) 20 7840 8400
        HYPERLINK "http://www.randomhouse.co.uk"http://www.randomho-use.co.uk
        HYPERLINK
        "http://www.booksattransworld.co.uk"http://www.booksatt-ransworld.-co.uk
        HYPERLINK
        "http://www.kidsatrandomhouse.co.uk"http://www.kidsatra-ndomhouse.-co.uk
        Generic email address - HYPERLINK
        "mailto:enquiries%40randomhouse.co.uk"enquiries@...

        Name & Registered Office:
        THE RANDOM HOUSE GROUP LIMITED
        20 VAUXHALL BRIDGE ROAD
        LONDON
        SW1V 2SA
        Random House Group Ltd is registered in the United Kingdom with company No.
        00954009, VAT number 102838980
        ************-*********-*********-*********-*********-*********-*********-***
        ******-********






        --
        No virus found in this incoming message.
        Checked by AVG Free Edition.
        Version: 7.5.432 / Virus Database: 268.17.15/659 - Release Date: 1/30/2007
        9:31 AM



        --
        No virus found in this outgoing message.
        Checked by AVG Free Edition.
        Version: 7.5.432 / Virus Database: 268.17.17/661 - Release Date: 1/30/2007
        11:30 PM



        [Non-text portions of this message have been removed]
      • Atkinson, Robert
        Please explain what you are trying to make, and perhaps I can give you the right code. Rob. ... From: php-objects@yahoogroups.com
        Message 3 of 16 , Feb 2, 2007
        • 0 Attachment
          Please explain what you are trying to make, and perhaps I can give you the
          right code.

          Rob.

          -----Original Message-----
          From: php-objects@yahoogroups.com [mailto:php-objects@yahoogroups.com] On
          Behalf Of Wolf Zscheile
          Sent: 02 February 2007 02:22
          To: php-objects@yahoogroups.com
          Subject: RE: [php-objects] convert a multidimensional array to javascript

          Hi Rob.,

          still got problems...

          Your code looks ok, but the output is in a 'bunch', how can I get the output
          for each individual item ?

          With Javascript I need
          var soundx= myArray[0][3];

          and to process this further

          soundManager.play('soundx');

          Please excuse the stupid questions of a Newbe..

          Greeting,

          Wolf

          ***********************************************************************************
          Any opinions expressed in email are those of the individual and not necessarily those of the company. This email and any files transmitted with it are confidential and solely for the use of the intended recipient
          or entity to who they are addressed. It may contain material protected by attorney-client privilege. If you are not the intended recipient, or a person responsible for delivering to the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited.

          Random House Group + 44 (0) 20 7840 8400
          http://www.randomhouse.co.uk
          http://www.booksattransworld.co.uk
          http://www.kidsatrandomhouse.co.uk
          Generic email address - enquiries@...

          Name & Registered Office:
          THE RANDOM HOUSE GROUP LIMITED
          20 VAUXHALL BRIDGE ROAD
          LONDON
          SW1V 2SA
          Random House Group Ltd is registered in the United Kingdom with company No. 00954009, VAT number 102838980
          ***********************************************************************************
        • Wolf Zscheile
          Hi Rob Thanks a lot for your continuing interest. I m just trying to figure out things and get organized.. As soon as I m through with that I will get in touch
          Message 4 of 16 , Feb 4, 2007
          • 0 Attachment
            Hi Rob

            Thanks a lot for your continuing interest. I'm just trying to figure out
            things
            and get organized..
            As soon as I'm through with that I will get in touch with you again.

            Thanks a lot,

            Wolf



            -----Original Message-----
            From: php-objects@yahoogroups.com [mailto:php-objects@yahoogroups.com] On
            Behalf Of Atkinson, Robert
            Sent: Friday, February 02, 2007 3:01 AM
            To: php-objects@yahoogroups.com
            Subject: RE: [php-objects] convert a multidimensional array to javascript



            Please explain what you are trying to make, and perhaps I can give you the
            right code.

            Rob.

            -----Original Message-----
            From: HYPERLINK
            "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
            [mailto:HYPERLINK
            "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com] On
            Behalf Of Wolf Zscheile
            Sent: 02 February 2007 02:22
            To: HYPERLINK
            "mailto:php-objects%40yahoogroups.com"php-objects@-yahoogroups.-com
            Subject: RE: [php-objects] convert a multidimensional array to javascript

            Hi Rob.,

            still got problems...

            Your code looks ok, but the output is in a 'bunch', how can I get the output
            for each individual item ?

            With Javascript I need
            var soundx= myArray[0][3]-;

            and to process this further

            soundManager.-play('soundx'-);

            Please excuse the stupid questions of a Newbe..

            Greeting,

            Wolf

            ************-*********-*********-*********-*********-*********-*********-***
            ******-********
            Any opinions expressed in email are those of the individual and not
            necessarily those of the company. This email and any files transmitted with
            it are confidential and solely for the use of the intended recipient
            or entity to who they are addressed. It may contain material protected by
            attorney-client privilege. If you are not the intended recipient, or a
            person responsible for delivering to the intended recipient, be advised that
            you have received this email in error and that any use is strictly
            prohibited.

            Random House Group + 44 (0) 20 7840 8400
            HYPERLINK "http://www.randomhouse.co.uk"http://www.randomho-use.co.uk
            HYPERLINK
            "http://www.booksattransworld.co.uk"http://www.booksatt-ransworld.-co.uk
            HYPERLINK
            "http://www.kidsatrandomhouse.co.uk"http://www.kidsatra-ndomhouse.-co.uk
            Generic email address - HYPERLINK
            "mailto:enquiries%40randomhouse.co.uk"enquiries@...

            Name & Registered Office:
            THE RANDOM HOUSE GROUP LIMITED
            20 VAUXHALL BRIDGE ROAD
            LONDON
            SW1V 2SA
            Random House Group Ltd is registered in the United Kingdom with company No.
            00954009, VAT number 102838980
            ************-*********-*********-*********-*********-*********-*********-***
            ******-********






            --
            No virus found in this incoming message.
            Checked by AVG Free Edition.
            Version: 7.5.432 / Virus Database: 268.17.17/661 - Release Date: 1/30/2007
            11:30 PM



            --
            No virus found in this outgoing message.
            Checked by AVG Free Edition.
            Version: 7.5.432 / Virus Database: 268.17.21/665 - Release Date: 2/2/2007
            11:39 PM



            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.