reading in multiarray

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Slaughter

    reading in multiarray

    I wrote some code to read in a file

    and I'm curious as to is this is a decent way to do it or if there is a much
    more elegant way. Essentially I want to convert a text file that into a ul
    in html for my nav menu. This way I can easily add and remove links without
    messing with any other code(Except of course where the link points to).

    Anyways, the code works as far as getting the links into a multi-array that
    I can work with but not sure if its the best way or not.

    --------Links.txt--------
    Home
    About
    Mathematics
    -Tutorials
    -Works
    -Other
    -Misc
    Computers
    -Tutorials
    -Misc


    <?php
    echo 'Opening Links.txt...<br >';

    $lines = file('./Links.txt');

    // Get links into array
    $s = 0;
    $k = -1;
    foreach ($lines as $line_num =$line)
    {

    if ($line[0] != '-')
    {
    $s = 0;
    $k++;
    $Links[$k][$s] = $line;
    } else
    {
    $s++;
    $Links[$k][$s] = $line;

    }

    }

    // print links.
    foreach ($Links as $link)
    {
    foreach ($link as $llink)
    {
    echo "$llink<br> ";
    }
    }


    ?>

    Thanks, Jon


  • Steve

    #2
    Re: reading in multiarray


    "Jon Slaughter" <Jon_Slaughter@ Hotmail.comwrot e in message
    news:NORVh.1282 $H_.157@newssvr 21.news.prodigy .net...
    |I wrote some code to read in a file
    |
    | and I'm curious as to is this is a decent way to do it or if there is a
    much
    | more elegant way. Essentially I want to convert a text file that into a ul
    | in html for my nav menu. This way I can easily add and remove links
    without
    | messing with any other code(Except of course where the link points to).
    |
    | Anyways, the code works as far as getting the links into a multi-array
    that
    | I can work with but not sure if its the best way or not.

    create table menu
    (
    id int not null primary ,
    parent int null default 0 ,
    node varchar(255) not null ,
    action text not null
    );

    now traverse the data to link each node to it's parent. you may only want to
    run this once. in that case, save the menu in a session var. if that var
    isn't set, you know you should build the menu again.

    i know i'm talking about databases, however a file is not an adequate
    solution...espe cially the kind of format you're talking about. an xml file
    *could* be a close second to what i've proposed and you could utilize xslt
    to render the menu. however, it's not as easily maintained as db data.


    Comment

    • gosha bine

      #3
      Re: reading in multiarray

      On 20.04.2007 00:11 Jon Slaughter wrote:
      I wrote some code to read in a file
      >
      and I'm curious as to is this is a decent way to do it or if there is a much
      more elegant way. Essentially I want to convert a text file that into a ul
      in html for my nav menu. This way I can easily add and remove links without
      messing with any other code(Except of course where the link points to).
      >
      Anyways, the code works as far as getting the links into a multi-array that
      I can work with but not sure if its the best way or not.

      Your code looks ok to me, however it won't work with deeply nested
      structures. Perhaps more scalable would be to store data in XML format.

      --
      gosha bine

      extended php parser ~ http://code.google.com/p/pihipi
      blok ~ http://www.tagarga.com/blok

      Comment

      • Jon Slaughter

        #4
        Re: reading in multiarray


        "gosha bine" <stereofrog@gma il.comwrote in message
        news:462879c1$0 $2890$6e1ede2f@ read.cnntp.org. ..
        On 20.04.2007 00:11 Jon Slaughter wrote:
        >I wrote some code to read in a file
        >>
        >and I'm curious as to is this is a decent way to do it or if there is a
        >much more elegant way. Essentially I want to convert a text file that
        >into a ul in html for my nav menu. This way I can easily add and remove
        >links without messing with any other code(Except of course where the link
        >points to).
        >>
        >Anyways, the code works as far as getting the links into a multi-array
        >that I can work with but not sure if its the best way or not.
        >
        >
        Your code looks ok to me, however it won't work with deeply nested
        structures. Perhaps more scalable would be to store data in XML format.
        Right now I'm not worried about more than 2 deep because I initially wrote
        my code and did my graphics only for 2D. Later I'm after I finish my web
        site I'm thinking about making it much more robust and redo everything(Sinc e
        I have learned a lot of new stuff already(first time doing html/css/php
        crap). I have a few ideas but I guess I really just need to get me a site
        up first and then I can worry about making it better.


        Thanks,
        Jon


        Comment

        • C.

          #5
          Re: reading in multiarray

          On 20 Apr, 11:30, "Jon Slaughter" <Jon_Slaugh...@ Hotmail.comwrot e:
          "gosha bine" <stereof...@gma il.comwrote in message
          >
          news:462879c1$0 $2890$6e1ede2f@ read.cnntp.org. ..
          >
          On 20.04.2007 00:11 Jon Slaughter wrote:
          I wrote some code to read in a file
          >
          and I'm curious as to is this is a decent way to do it
          Your code looks ok to me, however it won't work with deeply nested
          structures. Perhaps more scalable would be to store data in XML format.
          >
          Right now I'm not worried about more than 2 deep because I initially wrote
          my code and did my graphics only for 2D.
          You might want to take a look at php layers menu.

          C.

          Comment

          Working...