mendsley01 Posted February 6, 2009 Share Posted February 6, 2009 I am trying to create an unordered list with many depths to show the structure of a company. The problem I am having is the looping portion of the script. My idea is to have the script loop the depths out putting <li></li> until it comes to a higher depth than it will output <ul>. I have been racking my brain on how to close the <ul> at the end but I guess I am noot skilled enough. If some has some time to take a look and send me in the right direction I would appreciate it. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <?php $localhost = ""; $sql_username = ""; $sql_password = ""; $database = ""; //connect to database mysql_connect($localhost,$sql_username,$sql_password); @mysql_select_db($database) or die("Unable to select database for some reason!"); function display_children($parent) { $sql = "SELECT node.name, (COUNT(parent.name) - 1) AS depth ". "FROM test_tbl AS node, ". "test_tbl AS parent ". "WHERE node.lft BETWEEN parent.lft AND parent.rgt ". "GROUP BY node.name ". "ORDER BY depth DESC"; $result = mysql_query($sql); echo "<ul>\n"; while ($row = mysql_fetch_array($result)) { $b = $row['depth']; for( $a = 0; $a == $b; $a++ ) { echo "<li>".$row['name']."->".$row['depth']."</li>\n"; } $depth = $row['depth']; if ($depth == $depth-1) { echo "<ul>\n"; }else{ echo "</ul>\n"; } }//While close }//Function close echo display_children('TopMostParent'); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/144148-generating-unordered-list/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.