Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8333027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:53:10+00:00 2026-06-09T02:53:10+00:00

I have a recursive treeview which pulls all its information from a database and

  • 0

I have a recursive treeview which pulls all its information from a database and would like some insight as to how I can make it collapsible.
I tried using Jquery and Javascript but neither attempt had any effect. Not sure if was maybe just error on my part or something else.

here is my basic code:

<body>
<?php
mysql_connect('localhost', 'root');
mysql_select_db('test');


 $qry="SELECT * FROM treeview_items";
 $result=mysql_query($qry);


 $arrayCategories = array();

 while($row = mysql_fetch_assoc($result)){ 
 $arrayCategories[$row['id']] = array("parent_id" => $row['parent_id'], "name" =>                       
 $row['title']);   
  }
//createTree($arrayCategories, 0);

 function createTree($array, $currentParent, $currLevel = 0, $prevLevel = -1) {

foreach ($array as $categoryId => $category) {

if ($currentParent == $category['parent_id']) {                       

    if ($currLevel > $prevLevel) echo " <ul> "; 

    if ($currLevel == $prevLevel) echo " </li> ";

    echo '<li id="'.$categoryId.'" onclick=child(this.id);>       
 <span>'.$category['name'].'</span>';

    if ($currLevel > $prevLevel) { $prevLevel = $currLevel; }

    $currLevel++; 

    createTree ($array, $categoryId, $currLevel, $prevLevel);

    $currLevel--;               
    }   

}

if ($currLevel == $prevLevel) echo " </li>  </ul> ";

}   
?>
<div id="content" class="general-style1">
<?php
 if(mysql_num_rows($result)!=0)
 {
?>
<ul>
<li id="0" class="root"><span>Categories</span>
<?php createTree($arrayCategories, 0); ?>
</li>
</ul>
<?php
}
?>
</div>
</body>
</html>

Any help is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:53:12+00:00Added an answer on June 9, 2026 at 2:53 am

    I think it really worth to take a look at this css only approach for collapsible tree views: http://www.thecssninja.com/css/css-tree-menu With a few modifications it can be used for any kind of tree view that you might want to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a recursive function which can be written like: void func(TypeName *dataStructure, LL_Node
I have a TreeView which i build up in code recursively. I would like
I have a recursive immutable data structure in ocaml which can be simplified to
I have a recursive maze solver algorithm that can successfully work its way through
I have a recursive method call. When any exception is thrown, I would like
I have a recursive function which contains some drawing code inside. I was advised
Question: I have a view which I want to derive from a recursive query.
I have a big problem that a recursive treeview doesn't update any childs if
i have a recursive query like this (note: this is just an example): var
I have a recursive model like this: public class Node { public int Id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.