Dynamic Menu CSS - PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello there...
I am trying for a long time now, to find a way of creating a dynamic drop
down menu. I have the CSS part ready and working and also I have the first
level of the menu working.
the problem I have is how can I submit the id from the first level menu in
order to make the query and create the second level and so on menu.

I am trying to avoid Javascript but I can't see another way at the moment...
What I want to achieve is to produce the menu on HOVER if that is not
possible on click will be ok as well.
Do any of you have an idea ?

This is the code I have :
<div id="menu">
<?php do {   ?>
    <li><a href="?cat_id=<?php echo
($row_product_categories['prod_category_id']); ?>"title="<?php echo
strtoupper($row_product_categories['prod_category_name']); ?>"><?php echo
ucfirst($row_product_categories['prod_category_name']); ?></a></li>
<?php  }
   while ($row_product_categories =
mysql_fetch_assoc($rs_product_categories)); ?>

<?php do {   ?>
    <li><a href="index.php?id=<?php echo ($row_products['prod_id']);
?>"title="<?php echo strtoupper($row_products['prod_name']); ?>"><?php echo
ucfirst($row_products['prod_name']); ?></a></li>
<?php  }
   while ($row_products = mysql_fetch_assoc($rs_products)); ?>


Re: Dynamic Menu CSS - PHP

Angelos wrote:
Quoted text here. Click to load it

You should really look at the article "Son of Suckerfish Dropdowns"
http://www.htmldog.com/ptg/archives/000050.php for how to do the CSS

Quoted text here. Click to load it

You have to populate all of the levels of the menu structure at once by
looping through each product category for the products.

Here is my take on your code:

 $q1 = "select * from product_categories";
 $rs_product_categories = mysql_query($q1);
 $tmp = array(); // hold all output in a temporary array
 $tmp[] = '<div id="menu">';
 $tmp[] = '<ul>';
 $tmp[] = '<li><h2>Products</h2>';
 $tmp[] = "\t".'<ul>';
 while ($row_product_categories =
mysql_fetch_assoc($rs_product_categories)) {
   $prod_cat_id = $row_product_categories['prod_category_id'];
   $tmp[] = "\t\t".'<li><a href="' . $_SERVER['PHP_SELF'] . '?cat_id='
.. $prod_cat_id . '" title=' . strtoupper($prod_cat_id) . '>' .
ucfirst(strtolower($prod_cat_id)) . '</a>';
// create next level of menu here
   $tmp[] = "\t\t\t".'<ul>';
   $q2 = "select * from products where " // since I don't know your DB
structure, I can't fill this in ...
    $rs_products = mysql_query($q2);
    while ($row_products = mysql_fetch_assoc($rs_products)) {
        $prod_name = $row_products['row_name'];
        $tmp[] = "\t\t\t\t".'<li><a href="' . $_SERVER['PHP_SELF'] .
'?id='.$row_products['prod_id']. '" title=' .
strtoupper($row_products['prod_name']) . '>' .
ucfirst(strtolower($row_products['prod_name'])) . '</a></li>'; }
    $tmp[] = "\t\t\t".'</ul>';
    $tmp[] = "\t\t".'</li>';
  $tmp[] = "\t".'</ul>';
  $tmp[] = '</li></ul>';
  $tmp[] = '</div>';
  echo implode("\n".$tmp)."\n";


Re: Dynamic Menu CSS - PHP

That's the URL as well to have a look

Site Timeline