By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

Dynamic Menu CSS - PHP

P: n/a
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">
<ul>
<li><h2>Products</h2>
<ul>
<?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)); ?>
<ul>

<?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)); ?>

</ul>
</li>
</ul>
</li>
</ul>
</div>
**************************************************
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
That's the URL as well to have a look
http://www.workinprogress.co.uk/test/index.php
Jul 17 '05 #2

P: n/a
Angelos wrote:
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.
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
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.


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:

<?php
$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";
?>

Ken

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.