C2K Posted December 12, 2006 Share Posted December 12, 2006 I have a little problem with my code, the output is wrong, not what I want...:I'm using this now:[code]<?php function recursie($var){ $query2 = "SELECT * FROM ddc_menu_bck WHERE sitemap = 'Y' AND siteID = '". $_GET['siteID'] ."' AND subid = '". $var ."'"; $query1 = mysql_query($query2) or die(mysql_error()); if (mysql_num_rows($query1) > 0 ) { echo "<ul id=\"nav\">"; while($query = mysql_fetch_object($query1)){ echo "<li>". "<a href=\"" . $query->menuPag . "?mID=" . $query->mID . "&subID=" . $query->subID . "&siteID=" . $query->siteID . "\">" . $query->menuNaam ."</a>" . "</li>"; recursie($query->mID); } echo "</ul>"; }}?> [/code]Output:[code]<ul id="nav"> <li>home</li> <li>about us</li> <ul id="nav"> <li>more about us</li> </ul>[/code]but I want this as an output?[code]<ul id="nav"> <li>home</li> <li>about us <ul> <li>more about us</li> </ul> </li>[/code]How to get this right??I was trying also this:[code]<?phpfunction recursie($var, $level = 0){ $query2 = "SELECT * FROM ddc_menu_bck WHERE sitemap = 'Y' AND siteID = '". $_GET['siteID'] ."' AND subid = '". $var ."'"; $query1 = mysql_query($query2) or die(mysql_error()); if (mysql_num_rows($query1) > 0 ) { if($level == 0) echo "<ul id=\"nav\">"; else echo "<ul>"; while($query = mysql_fetch_object($query1)) { echo "<li>". "<a href=\"" . $query->menuPag . "?mID=" . $query->mID . "&subID=" . $query->subID . "&siteID=" . $query->siteID . "\">" . $query->menuNaam ."</a>" . "</li>"; recursie($query->mID, $level++); } echo "</ul>"; }}?> [/code] Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/ Share on other sites More sharing options...
Psycho Posted December 12, 2006 Share Posted December 12, 2006 The 2nd one should work as long as you are passing the correct $level values to the function. I allways prefer to put my if/else code within curly braces myself. Since level would be false (i.e. 0) for anything other than the top level you could change the condition to just (!$level) if(!$level) { echo "<ul id=\"nav\">"; } else { echo "<ul>"; } Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-139962 Share on other sites More sharing options...
mlacy03 Posted December 12, 2006 Share Posted December 12, 2006 If you are using the IDs purely for formatting, CSS2 has a :first-child selector you might find useful:[url=http://www.w3.org/TR/1998/REC-CSS2-19980512/selector.html#first-child]Selectors, First-Child[/url] Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-139967 Share on other sites More sharing options...
C2K Posted December 12, 2006 Author Share Posted December 12, 2006 OKe thanks for your reply.How get I the open <LI> to work... I want this for an output:<UL id="nav"> <LI>some menu <UL> <LI>some menu item</LI> </UL> </LI></UL> Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-139972 Share on other sites More sharing options...
C2K Posted December 12, 2006 Author Share Posted December 12, 2006 [quote author=mlacy03 link=topic=118368.msg483631#msg483631 date=1165963106]If you are using the IDs purely for formatting, CSS2 has a :first-child selector you might find useful:[url=http://www.w3.org/TR/1998/REC-CSS2-19980512/selector.html#first-child]Selectors, First-Child[/url][/quote]Use the ID's for main and parent selctors for the unsorted list?! Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-139979 Share on other sites More sharing options...
mlacy03 Posted December 12, 2006 Share Posted December 12, 2006 I was thinking of something like:[code]<style>div > ul#nav:first-child { background-color:red; }</style><div> // needed for ul to be first-child of, nothing more<ul id=nav> <li>Test</li> <li> <ul> <li>Second Level</li> <li>Test</li> </ul> </li></ul></div>[/code] Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-139982 Share on other sites More sharing options...
C2K Posted December 13, 2006 Author Share Posted December 13, 2006 It's maybe possible, but no solutions for my problem, I want to use it with the suckerfish dropdown... and IE is displayed oke, but that not oke, Firefox has a better CSS interpertation and displayed it wrong ofcourse!Please some help with the PHP Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-140021 Share on other sites More sharing options...
C2K Posted December 13, 2006 Author Share Posted December 13, 2006 Is there a better way of making a dropdown menu with PHP recursive and CSS? Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-140273 Share on other sites More sharing options...
C2K Posted December 13, 2006 Author Share Posted December 13, 2006 Is there no one used this option of making menu's??Fred Link to comment https://forums.phpfreaks.com/topic/30410-recursive-menu-unsorted-list-little-problem/#findComment-140359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.