Page 1 of 1

do-while menu problem

Posted: Mon Feb 07, 2011 12:21 pm
by andresfz87
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:

Code: Select all

<?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 subitems.. where is the problem?

edit: if I add the line

Code: Select all

<?php echo $row_sections['id']; ?>
right before the second

Code: Select all

<?php do{ ?>
it shows the corresponding ID for BOTH sections so I can't understand the problem...