Page 1 of 1

PHP / Mysql Printing sub buttons of buttons

Posted: Tue Jan 10, 2006 4:42 am
by rm
Hi,

I have this dynamic menu but i cannot find the way on how to print a sub buttons inside a list.

I would like to achieve:

<ul>
<li> button 1
(echo sub button)
<ul>
<li> sub button 1.1 </li>
</ul>
(finished echo sub button)
</li>
</ul>

This is the php bit i got:

Code: Select all

<?php
include('common.php');
// Connect to database
dbConnect();

$qry = "select * from menu where menu_parent='' and menu_enabled='Y' order by menu_name asc";
$rst = mysql_query($qry);
echo '<ul>'."\n";
while($row=mysql_fetch_array($rst)) {
	echo "\t".'<li><a href="showmenu.php?p='.$row['menu_id'].'">'.$row['menu_name'].'</a>'.'</li>'."\n";
	if($_GET['p']==$row['menu_id']) {
		$qry2 = "select * from menu where menu_parent='$row[menu_id]' and menu_enabled='Y' order by menu_name asc";
		$rst2 = mysql_query($qry2);
		while($row2=mysql_fetch_array($rst2)) {
echo '<ul>'."\n";
echo "\t".'<li><a href="showmenu.php?p='.$row['menu_id'].'&pg='.$row2['menu_id'].'">'.$row2['menu_name'].'</a></li>'."\n";
echo '<\ul>'."\n";
		}
	}
}
echo '</ul>'."\n";
?>
Thanks guys.

RM

Posted: Tue Jan 10, 2006 5:25 am
by mickd
you have to nest a loop in another loop, for example

Code: Select all

while(fetch to get buttons) {
   while(fetch to get sub buttons) {

   }
}
or something else like that

Posted: Tue Jan 10, 2006 7:59 am
by rm
Erf...yeah...theoretically i got that, but any chance you guys can give me a more my code related example?

Thx in advance