rather noob trouble w/ tree expanding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Milan Krejci

    rather noob trouble w/ tree expanding

    the thing is that descentant branches i dont want to expand do expand.
    $id variable contains an array of branches i want the program to go
    through (alcohol's id -beer id etc)

    function tree_list($pare nt, $level,$id) {
    // retrieve all children of $parent

    $result = mysql_query('SE LECT cname,cid FROM kategorie '.
    'WHERE parent="'.$pare nt.'";');
    while ($row = mysql_fetch_arr ay($result)) {
    echo str_repeat('&nb sp;&nbsp;',$lev el).$row['cname']."<br/>\n";

    if ($row['cid']==$id[$level])
    $this->tree_vypis($ro w['cid'], $level+1);
    }
    }
  • Kimmo Laine

    #2
    Re: rather noob trouble w/ tree expanding

    Milan Krejci kirjoitti:
    the thing is that descentant branches i dont want to expand do expand.
    $id variable contains an array of branches i want the program to go
    through (alcohol's id -beer id etc)
    >
    function tree_list($pare nt, $level,$id) {
    // retrieve all children of $parent
    >
    $result = mysql_query('SE LECT cname,cid FROM kategorie '.
    'WHERE parent="'.$pare nt.'";');
    while ($row = mysql_fetch_arr ay($result)) {
    echo str_repeat('&nb sp;&nbsp;',$lev el).$row['cname']."<br/>\n";
    >
    if ($row['cid']==$id[$level])
    $this->tree_vypis($ro w['cid'], $level+1);
    }
    }
    Sorry but I don't understand what the problem is. There seems to be some
    sort of recursive hierarchy tree structure involved but that's all I
    get. Also it would be nice to know what the method tree_vypis does. Try
    reformatting the question. What exactly is the _problem_?

    Btw: A noob using classes and recursion? A case of cut'n'paste coding?

    --
    "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
    spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)

    Comment

    • Rik

      #3
      Re: rather noob trouble w/ tree expanding

      Kimmo Laine <spam@outolempi .netwrote:
      Milan Krejci kirjoitti:
      >the thing is that descentant branches i dont want to expand do expand..
      >$id variable contains an array of branches i want the program to go
      >through (alcohol's id -beer id etc)
      > function tree_list($pare nt, $level,$id) {
      > // retrieve all children of $parent
      > $result = mysql_query('SE LECT cname,cid FROM kategorie '.
      > 'WHERE parent="'.$pare nt.'";');
      > while ($row = mysql_fetch_arr ay($result)) {
      > echo str_repeat('&nb sp;&nbsp;',$lev el).$row['cname']."<br/>\n";
      > if ($row['cid']==$id[$level])
      > $this->tree_vypis($ro w['cid'], $level+1);
      > }
      >}
      >
      Sorry but I don't understand what the problem is. There seems to be some
      sort of recursive hierarchy tree structure involved but that's all I
      get. Also it would be nice to know what the method tree_vypis does.
      Also, what this mysterious $id does, and why it is not fed down the
      recursion like the rest.
      Btw: A noob using classes and recursion? A case of cut'n'paste coding?
      Nah, I made (local test-)server crashing recursions and classes the first
      week I used PHP :P


      --
      Rik Wasmus
      Posted on Usenet, not any forum you might see this in.
      Ask Smart Questions: http://tinyurl.com/anel

      Comment

      • Rik

        #4
        Re: rather noob trouble w/ tree expanding

        Rik <luiheidsgoeroe @hotmail.comwro te:
        >Milan Krejci kirjoitti:
        >>$id variable contains an array of branches i want the program to go
        >>through (alcohol's id -beer id etc)
        Also, what this mysterious $id does, and why it is not fed down the
        recursion like the rest.
        D'OH

        But it surely indicates the problem: $id should be in the recursion too.
        Assuming you translated your function's name and actually tree_vypis ==
        tree_list:

        $trail = array(
        1 ='<drink_id>',
        2 ='<alcohol_id>' ,
        3 ='<beer_id>',
        4 ='<grolsch_id>' ); //Grolsch!

        function tree_list($pare nt=0,$level=1,$ trail=array()) {
        // retrieve all children of $parent
        $result = mysql_query("SE LECT cname,cid FROM kategorie
        WHERE parent='{$paren t}');
        while ($row = mysql_fetch_ass oc($result)) {
        echo str_repeat('&nb sp;&nbsp;',$lev el).$row['cname']."<br/>\n";
        if ($row['cid'] == $id[$level]) tree_list($row['cid'],
        $level+1,$trail );
        }
        }

        tree_list(0,1,$ trail);

        Then again, the previous posted function would result in _less_ expansion
        instead of more... (And a notice that $id did not exist, and certainly was
        no array). Seems like someone did not post the exact function as actually
        used?

        --
        Rik Wasmus
        Posted on Usenet, not any forum you might see this in.
        Ask Smart Questions: http://tinyurl.com/anel

        Comment

        • rdw

          #5
          Re: rather noob trouble w/ tree expanding

          Kimmo Laine wrote:
          Milan Krejci kirjoitti:
          >the thing is that descentant branches i dont want to expand do expand.
          >$id variable contains an array of branches i want the program to go
          >through (alcohol's id -beer id etc)
          >>
          >function tree_list($pare nt, $level,$id) {
          > // retrieve all children of $parent
          >>
          > $result = mysql_query('SE LECT cname,cid FROM kategorie '.
          > 'WHERE parent="'.$pare nt.'";');
          > while ($row = mysql_fetch_arr ay($result)) {
          > echo str_repeat('&nb sp;&nbsp;',$lev el).$row['cname']."<br/>\n";
          >>
          > if ($row['cid']==$id[$level])
          > $this->tree_vypis($ro w['cid'], $level+1);
          > }
          >}
          >
          Sorry but I don't understand what the problem is. There seems to be some
          sort of recursive hierarchy tree structure involved but that's all I
          get. Also it would be nice to know what the method tree_vypis does. Try
          reformatting the question. What exactly is the _problem_?
          >
          Btw: A noob using classes and recursion? A case of cut'n'paste coding?
          i may have been using linux and php for a couple of years. when i cut n
          pasted the code i realized it wasnt almost different from what i wrote
          >
          the program expands tree from a typical (category name, category id and
          category parent) mysql db. the trouble is that i get
          Alkohol
          Beer
          f
          e
          Likery
          Bozkov
          Citrus
          Fernet
          Vodka
          Chipsy
          Noviny

          when i wanted the Beer branch stay collapsed. i wanted only to list
          Likery->Bozkov.

          Comment

          • rdw

            #6
            Re: rather noob trouble w/ tree expanding PROBLEM SOLVED

            Rik wrote:
            Rik <luiheidsgoeroe @hotmail.comwro te:
            >>Milan Krejci kirjoitti:
            >>>$id variable contains an array of branches i want the program to go
            >>>through (alcohol's id -beer id etc)
            >
            >Also, what this mysterious $id does, and why it is not fed down the
            >recursion like the rest.
            >
            D'OH
            >
            But it surely indicates the problem: $id should be in the recursion too.
            Assuming you translated your function's name and actually tree_vypis ==
            tree_list:
            >
            $trail = array(
            1 ='<drink_id>',
            2 ='<alcohol_id>' ,
            3 ='<beer_id>',
            4 ='<grolsch_id>' ); //Grolsch!
            >
            function tree_list($pare nt=0,$level=1,$ trail=array()) {
            // retrieve all children of $parent
            $result = mysql_query("SE LECT cname,cid FROM kategorie
            WHERE parent='{$paren t}');
            while ($row = mysql_fetch_ass oc($result)) {
            echo str_repeat('&nb sp;&nbsp;',$lev el).$row['cname']."<br/>\n";
            if ($row['cid'] == $id[$level]) tree_list($row['cid'],
            $level+1,$trail );
            }
            }
            >
            tree_list(0,1,$ trail);
            >
            Then again, the previous posted function would result in _less_
            expansion instead of more... (And a notice that $id did not exist, and
            certainly was no array). Seems like someone did not post the exact
            function as actually used?
            >
            --Rik Wasmus
            Posted on Usenet, not any forum you might see this in.
            Ask Smart Questions: http://tinyurl.com/anel
            THANK you how could i overlook 2 stupid mistakes... typical :)

            Comment

            Working...