Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a recursive treeview collapsible
    primarykey
    data
    text
    <p>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.</p> <p>here is my basic code:</p> <pre><code>&lt;body&gt; &lt;?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" =&gt; $row['parent_id'], "name" =&gt; $row['title']); } //createTree($arrayCategories, 0); function createTree($array, $currentParent, $currLevel = 0, $prevLevel = -1) { foreach ($array as $categoryId =&gt; $category) { if ($currentParent == $category['parent_id']) { if ($currLevel &gt; $prevLevel) echo " &lt;ul&gt; "; if ($currLevel == $prevLevel) echo " &lt;/li&gt; "; echo '&lt;li id="'.$categoryId.'" onclick=child(this.id);&gt; &lt;span&gt;'.$category['name'].'&lt;/span&gt;'; if ($currLevel &gt; $prevLevel) { $prevLevel = $currLevel; } $currLevel++; createTree ($array, $categoryId, $currLevel, $prevLevel); $currLevel--; } } if ($currLevel == $prevLevel) echo " &lt;/li&gt; &lt;/ul&gt; "; } ?&gt; &lt;div id="content" class="general-style1"&gt; &lt;?php if(mysql_num_rows($result)!=0) { ?&gt; &lt;ul&gt; &lt;li id="0" class="root"&gt;&lt;span&gt;Categories&lt;/span&gt; &lt;?php createTree($arrayCategories, 0); ?&gt; &lt;/li&gt; &lt;/ul&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Any help is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload