php - Recursive function in Laravel 5.2 -
i want make recursive function , pass view build category, sub-category in laravel 5.2 , how create route , view , contrller code ..... code ..can me ?
<?php mysql_connect('localhost', 'root','123'); mysql_select_db('test'); $qry="select * 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['name']); } function createtree($array, $currentparent, $currlevel = 0, $prevlevel = -1) { foreach ($array $categoryid => $category) { if ($currentparent == $category['parent_id']) { if ($currlevel > $prevlevel) echo " <ul class='tree'> "; if ($currlevel == $prevlevel) echo " </li> "; echo '<li> <a href="#">'.$category['name'].'</a > '; if ($currlevel > $prevlevel) { $prevlevel = $currlevel; } $currlevel++; createtree ($array, $categoryid, $currlevel, $prevlevel); $currlevel--; } } if ($currlevel == $prevlevel) echo " </li> </ul> "; } ?> <?php if(mysql_num_rows($result)!=0) { ?> <?php createtree($arraycategories, 0); ?> <?php } ?> </div>
i think solution here: https://github.com/etrepat/baum
this automatically work for.
Comments
Post a Comment