andresfz87 Posted February 9, 2011 Share Posted February 9, 2011 I have a table in my db with all my menus and submenues of my site, I'd like to show them in some kind of menu containing all of them each entry in db has the columns ID,NAME,TEXT,LEVEL,DEPENDENT level has a value of 1 or 2 depending if it's an item or a subitem dependent has a reference to the id of the section it belongs to Using dreamweaver I created two recordsets based on the level, they are called row_sections (only where level = 1) and row_subsections (only where level = 2) here is the code I tried to use: <?php do { ?> <p><a href="test.php?sec=<?php echo $row_sections['id'];?>"><?php echo $row_sections['name']; ?></a></p> //prints the section text <?php do { ?> <?php if($row_subsections['dependent'] == $row_sections['id']) { echo $row_subsections['name']."<br>"; //tries to print all subitems corresponding to the actual item } ?> <?php } while ($row_subsections = mysql_fetch_assoc($subsections)); ?> <?php } while ($row_sections = mysql_fetch_assoc($sections)); ?> Here's the output: section 1 title subsection 1 subsection 2 section 2 title both section 1 and 2 should have two different subitems.. where is the problem? if I add the line <?php echo $row_sections['id']; ?> right before the second <?php do{ ?> it shows the corresponding ID for BOTH sections so I can't understand the problem... Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 9, 2011 Share Posted February 9, 2011 curious: is that do() your looping structure, or dreamweaver's? Quote Link to comment Share on other sites More sharing options...
andresfz87 Posted February 10, 2011 Author Share Posted February 10, 2011 Is dreamweaver's, I made both of them separately and then tried to combine them as I thought it would work but had no luck yet Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 in your code all do loops should be while loops while ($row_subsections = mysql_fetch_assoc($subsections)) { // do something with $row_subsections } otherwise, $row_subsections is not set to anything the first time through. i thought it odd, which is why i guessed dreamweaver did it. i leave dreamweaver as soon as design is finished. Quote Link to comment Share on other sites More sharing options...
andresfz87 Posted February 10, 2011 Author Share Posted February 10, 2011 I tried only with the code you sugested (please correct me if i'm wrong): <?php while ($row_sections = mysql_fetch_assoc($sections)){ ?> <p><a href="test.php?sec=<?php echo $row_sections['id'];?>"><?php echo $row_sections['name']; ?></a></p> <?php echo $row_sections['id']; ?> //this is to show current id to see if it works <?php } ?> Instead of looping it seems to skip to the last record (section 2 title) and show it as the only result, should show 2 records. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 10, 2011 Share Posted February 10, 2011 my post was an example. you still need to add the loop within that loop. another example: while ($row_subsections = mysql_fetch_assoc($subsections)) { // do something with $row_subsections } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.