User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 402,446 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,974 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 8023 | Replies: 6
Reply
Join Date: Jan 2006
Posts: 8
Reputation: snowweb is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
snowweb snowweb is offline Offline
Newbie Poster

Help php/mysql dynamic multi-level menu problem

  #1  
Jan 24th, 2006
I am trying to implement a CSS hierarchical unfolding menu on a site. The thing is, it needs to be dynamically populated from the results of a database query. I previously had the menu working but then it was ‘hard coded’ and not built on the fly.

Menu description:

2 top level items “Company� and “Products� (we will ignore “Company� since it is still hard coded and not causing a problem.

Below “Products� we have hard coded “By Manufacturer�. So you hover over “Products� and it unfolds and “By Manufacturer� is visible. If you hover over that, a list of manufacturers should open to the right. This list is extracted from the data base using SELECT DISTINCT.

Then if you hover over a manufacturer, another level unfolds which should contain the products of that manufacturer.

My problem is that the list of products includes all products in the database, not just those from the relevant manufacturer. The menus of the other manufacturers are empty.

The manufacturer under which all the products appear, is the manufacturer of the first product in the database.

[PHP]
<? require("inc/connect.txt");
/* Connecting to a database and retrieve data */
$mysql_access = mysql_connect("localhost", "$un", "$pw") or die("Error connecting to database server: ".mysql_error());
mysql_select_db($db, $mysql_access) or die("Error connecting to database: ".mysql_error());//always gotta do some error checking...

/* Get list of unique manufacturers */
$result_manu = mysql_query("SELECT DISTINCT `Manufacturer` FROM `products`");

/* Get list of products and details */
$result = mysql_query("SELECT `ProdID`,`Manufacturer`, `NameModel` FROM `products`");

//always gotta do some error checking...
if (!$result)
{exit("Error in SQL");} ?>

<!-- Begin unfolding menu code/structure when viewed without the accompanying stylesheet, it should display as a multi-level list of links which makes it easy to see which category items are in. -->

<ul id="nav">

<li>
<a href="aboutus.php">Company</a>
<ul>
<li>
<a href="index.php">Home Page</a>
</li>
<li>
<a href="aboutus.php">About us</a>
</li>
<li>
<a href="contactus.php">Contact us</a>
</li>
</ul>
</li>

<li>
<a href="#">Products</a>
<ul>
<li>
<a href="" class="daddy">By manufacturer</a>
<ul>
<? while ($resultset = mysql_fetch_assoc($result_manu))

{
$Manufacturer=$resultset['Manufacturer'];
echo "<li>";
echo "<a href='' class='daddy'>$Manufacturer</a>";
echo "<ul>";
while ($resultset2 = mysql_fetch_assoc($result))
{
$ProdID=$resultset2['ProdID'];
$NameModel=$resultset2['NameModel'];
echo "<li>";
echo "<a href='products.php?ProdID=$ProdID'>$NameModel</a>";
echo "</li>";
}
echo "</ul>";
echo "</li>";
}?>
</ul>
</li>
</ul>
</li>
</ul>
[/PHP]

Below is the code which is rendered by the browser when displayed without the appropriate CSS stylesheet and JavaScript that makes it work.
[HTML]

<!-- Begin unfolding menu code/structure when viewed without the accompanying stylesheet, it should display as a multi-level list of links which makes it easy to see which category items are in. -->

<ul id="nav">

<li>
<a href="aboutus.php">Company</a>
<ul>
<li>
<a href="index.php">Home Page</a>
</li>
<li>
<a href="aboutus.php">About us</a>
</li>
<li>
<a href="contactus.php">Contact us</a>
</li>
</ul>
</li>

<li>
<a href="#">Products</a>
<ul>
<li>
<a href="" class="daddy">By manufacturer</a>
<ul>
<li><a href='' class='daddy'>Kenwood</a>
<ul>
<li>
<a href='products.php?ProdID=1'>TK-270G/370G</a>
</li>
<li>
<a href='products.php?ProdID=4'>tester</a>
</li>
<li>
<a href='products.php?ProdID=5'>Chef</a>
</li>
</ul>
</li>
<li><a href='' class='daddy'>test manufacturer</a>
<ul>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
[/HTML]

...and this is the code that I am aiming to have rendered..

[HTML]

<!-- Begin unfolding menu code/structure when viewed without the accompanying stylesheet, it should display as a multi-level list of links which makes it easy to see which category items are in. -->

<ul id="nav">

<li>
<a href="aboutus.php">Company</a>
<ul>
<li>
<a href="index.php">Home Page</a>
</li>
<li>
<a href="aboutus.php">About us</a>
</li>
<li>
<a href="contactus.php">Contact us</a>
</li>
</ul>
</li>

<li>
<a href="#">Products</a>
<ul>
<li>
<a href="" class="daddy">By manufacturer</a>
<ul>
<li><a href='' class='daddy'>Kenwood</a>
<ul>
<li>
<a href='products.php?ProdID=1'>TK-270G/370G</a>
</li>
<li>
<a href='products.php?ProdID=5'>Chef</a>
</li>
</ul>
</li>
<li><a href='' class='daddy'>test manufacturer</a>
<ul>
<li>
<a href='products.php?ProdID=4'>tester</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
[/HTML]

I've a feeling that I'm close. Can anyone see my mistake please?

kind regards

pete
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Posts: 8
Reputation: snowweb is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
snowweb snowweb is offline Offline
Newbie Poster

Re: php/mysql dynamic multi-level menu problem

  #2  
Jan 25th, 2006
Thanks, this is now resolved.
Reply With Quote  
Join Date: Jun 2007
Posts: 1
Reputation: SoccerDad is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SoccerDad SoccerDad is offline Offline
Newbie Poster

Re: php/mysql dynamic multi-level menu problem

  #3  
Jun 17th, 2007
Just for anyone else who happens upon this thread and are as irritated as I am with folks who post "It's Fixed", but don't have the courtesy to say how they fixed it, the original poster appears to have gotten "it fixed" over here:

http://www.thescripts.com/forum/thread449155.html
Reply With Quote  
Join Date: Jan 2006
Posts: 8
Reputation: snowweb is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
snowweb snowweb is offline Offline
Newbie Poster

Re: php/mysql dynamic multi-level menu problem

  #4  
Feb 5th, 2008
and why should I waste my time explaining how I fixed it when NO-ONE on this forum gave me even the slightest help?

- Courtesy works both ways... not just one!
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: php/mysql dynamic multi-level menu problem

  #5  
Feb 5th, 2008
Originally Posted by snowweb View Post
and why should I waste my time explaining how I fixed it when NO-ONE on this forum gave me even the slightest help?

- Courtesy works both ways... not just one!


Well, people might not be knowing the answer for your question. You can't expect them to know the answer for everything. Can you ? And If you had posted your 'fix', it would have helped others who might have encountered the same problem. If your attitude is, 'why should I waste my time explaining blah blah blah', why do you expect help from others ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,227
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 10
Solved Threads: 270
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: php/mysql dynamic multi-level menu problem

  #6  
Feb 6th, 2008
LOL, I'm actually supriced he replayed as the original post is 2 years old now
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: php/mysql dynamic multi-level menu problem

  #7  
Feb 6th, 2008
Originally Posted by peter_budo View Post
LOL, I'm actually supriced he replayed as the original post is 2 years old now


Prolly he came back today after a long break !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 2:57 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC