PHP / Mysql Printing sub buttons of buttons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rm
Forum Newbie
Posts: 2
Joined: Tue Jan 10, 2006 4:35 am
Location: london

PHP / Mysql Printing sub buttons of buttons

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post 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
rm
Forum Newbie
Posts: 2
Joined: Tue Jan 10, 2006 4:35 am
Location: london

Post 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
Post Reply