SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to loop them out?

    `print_r($tree)` result is


    Array
    (
    [0] => stdClass Object
    (
    [tid] => 6
    [vid] => 2
    [name] => parent one
    [description] =>
    [format] => filtered_html
    [weight] => 0
    [depth] => 0
    [parents] => Array
    (
    [0] => 0
    )

    )

    [1] => stdClass Object
    (
    [tid] => 14
    [vid] => 2
    [name] => child one
    [description] =>
    [format] => filtered_html
    [weight] => 0
    [depth] => 1
    [parents] => Array
    (
    [0] => 6
    )

    )

    [2] => stdClass Object
    (
    [tid] => 13
    [vid] => 2
    [name] => child tow
    [description] =>
    [format] => filtered_html
    [weight] => 0
    [depth] => 1
    [parents] => Array
    (
    [0] => 6
    )

    )

    [3] => stdClass Object
    (
    [tid] => 7
    [vid] => 2
    [name] => parent two
    [description] =>
    [format] => filtered_html
    [weight] => 1
    [depth] => 0
    [parents] => Array
    (
    [0] => 0
    )

    )

    [4] => stdClass Object
    (
    [tid] => 18
    [vid] => 2
    [name] => child three
    [format] => filtered_html
    [weight] => 0
    [depth] => 1
    [parents] => Array
    (
    [0] => 7
    )

    )

    [5] => stdClass Object
    (
    [tid] => 19
    [vid] => 2
    [name] => child four
    [format] => filtered_html
    [weight] => 0
    [depth] => 1
    [parents] => Array
    (
    [0] => 7
    )

    )

    [6] => stdClass Object
    (
    [tid] => 8
    [vid] => 2
    [name] =>parent
    [description] =>
    [format] => filtered_html
    [weight] => 2
    [depth] => 0
    [parents] => Array
    (
    [0] => 0
    )

    )

    [7] => stdClass Object
    (
    [tid] => 4
    [vid] => 2
    [name] => parent
    [description] =>
    [format] => filtered_html
    [weight] => 3
    [depth] => 0
    [parents] => Array
    (
    [0] => 0
    )

    )


    i want to output the hml like the following:


    <li class='parent'><a href="#">parent one</a><span></span>
    <ul class='haschild'>
    <li><a href="#">child one/a></li>
    <li><a href="#">child two</a></li>
    </ul>
    </li>
    <li class='parent'><a href="">parent two</a><span></span>
    <ul class='haschild'>
    <li><a href="">child three</a></li>
    <li><a href="9">child four</a></li>
    </ul>
    </li>
    <li><a href="">parent</a></li>
    <li><a href="">parent</a></li>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Can a child have more than one parent? Can a parent have more than one child? A simple foreach will not do here.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Can a child have more than one parent? Can a parent have more than one child? A simple foreach will not do here.
    a child have only one child,a parent maybe have more than one child?

  5. #5
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    foreeach($tree as $term){

    if($term->path==0){
    echo "<li class='parent'><a href=''>$term->name</li>";
    }
    if()..

    i don't now how to write the code. could you give me withe more details.

  6. #6
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Can a child have more than one parent? Can a parent have more than one child? A simple foreach will not do here.
    if it has child add class='parent' to the li, add the ul out of all the child li


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •