Javascript to PHP Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paulgrimshaw
    New Member
    • Oct 2006
    • 11

    Javascript to PHP Array

    Hi,

    I have been working on this for a while and can not figure out how to do it. This is the story to explain what I am doing:

    I use Actinic website software and I am currently using a javascript function to take an array of section names etc and create a menu. This is quite large and I am moving to php as Actinic has php inside and creates the html before uploading. Actinic creates a javascript file. This file is referenced by another js file that creates the menu by running a few nested ifs to create individual IDs that can be manipulated later by another js file.

    I have no idea how I can take this file and create a php array. Everything else is ready to go, I just need the array! The js file is located in my local folder and that is where I will reference it. I am also only going to create an array with two vars (sName & sUrl).

    There is a copy js file with the array here: http://www.madmash.com/acatalog/Act_section_tre e.js

    The js file that uses the array is here if it helps?:
    http://www.madmash.com/acatalog/replaceo_menu.j s

    Can anyone help?

    Thanks,
    Paul.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    When you made the js array into a PHP array, how would you want to traverse it? Have you already made php code to do that?

    Ronald :cool:

    Comment

    • paulgrimshaw
      New Member
      • Oct 2006
      • 11

      #3
      Hi, thanks for your reply.

      I have the code in JS at the moment, but it would be quite easy to change to php so this is what I was going to do - it needs to be in the order it comes in as the menu runs by using an ID per div that is created in parts (i.e. 2.3.4) as it runs through the nested ifs. Here is the basic structure with the gumpf taken out.

      Code:
      function YahooSections(ar)
      {
        for (var i=0; i < ar.length; i++) //for every Top Level
           {
              if (ar[i+1].pChild) //if Top Level has a Second Level
                 {
                    blah
                    for (var j=1; j <=ar[i+1].pChild.length; j++) // if Second Level has items/headers exist process them
                      {
                         blah
                         if (ar[i+1].pChild[j].pChild) //if Second Level has Third Level
                           {
                              blah
                              for (var k=1; k <=ar[i+1].pChild[j].pChild.length; k++)
                                {
                                  if (ar[i+1].pChild[j].pChild[k].pChild) //if Third Level has Fourth Level
                                    blah
                                  else
                                    blah
                                }
                           }
                         else 
                           {
                              blah
                           }
                      }
                 } 
              else
                 blah
          }
      }
      If there are better ways of doing this that acomplish the same thing then thats fine too.

      Thanks,
      Paul.

      Comment

      • darkdirk1
        New Member
        • Oct 2006
        • 50

        #4
        You simply will not be able to get away from using the POST method.
        I wish there was another way...
        If there is an alternative I hope someone shares it w/ both of us.

        Why are you sending this info back to the server anyway?
        Is it with the intent of writing to a db???
        If so, prepare yourself for a whole other list() of problems.

        Comment

        • paulgrimshaw
          New Member
          • Oct 2006
          • 11

          #5
          Hi,

          I dont need to send it to a database or even post it. This will run locally and just create the html code for the my menu system from the array supplied. At the moment when the page opens I have some java (thats what is quoted above) that moves through the array (which happens to be another java file) and creates the html. This is then show to the user. I want to simply change this to perl and get rid of java for the menu creation.

          If I simplify this just so I can try and get an answer to this specific question, it would get me a long way to where I am trying to be.

          This is a bit from the java/array file that I have and I can not change the format, so whatever I do it will need to somehow manipulate it if it isnt ready for php.

          section_tree[1].sName = "Brands";
          section_tree[1].pChild[1].sName = "Block";
          section_tree[1].pChild[2].sName = "TDI";
          How would I traverse the array so that I can say. if section_tree[1] has child (i.e. section_tree[1].pChild then go do something else dont (etc).

          Thanks
          Paul.

          Comment

          • paulgrimshaw
            New Member
            • Oct 2006
            • 11

            #6
            Hi, Just bumping this incase anyone has any ideas. Won't bump again.

            Thanks,
            Paul.

            Comment

            Working...