arrays - PHP create a hierarchy menu structure -
arrays - PHP create a hierarchy menu structure -
basically have table in mysql
name id parent bob 321 root sue 32 root boo 393 32 geek 72 393 sam 312 393 tovoc 341 321 reese 322 393 sheep 811 341 i want create menu outputs menu construction submenus based on parent id
so should output
bob tovoc sheep sue boo sam geek reese the kid entries linked parent id , if have parent become child. build multidimentual array. clues?
heres got far. works, can't figure out how increment or reset margin style nice construction view. have margin-left increment 10px in every kid elements found, reset 1 if parent user
isparent(user,1); function isparent($parent,$if=1){ $stdr = 'select * cravebins userid = '.$_session[craveuserid].' , parent=\''.$parent.'\' order name asc'; $resultmainmenu = mysql_query($stdr) or die('421 '.$stdr.mysql_error()); if(mysql_num_rows($resultmainmenu)){ while($row = mysql_fetch_array($resultmainmenu)){ $if++; echo '<div class="bindir" onclick="setbin(this)" id="binlistuser" style="margin-left:'.(5+($if * 10)).'px" driid="'.$row[id].'">'.$row['name'].'</div>'; // echo main menu $n = isparent($row['id'],$if); }//end while }else{ $if=1; } // if rows }//end function php arrays menu
Comments
Post a Comment