Solved

nested loop accordian menus

Posted on 2009-07-06
9
431 Views
Last Modified: 2013-11-19
I have a function for creating a nested UL based on data in my MYSQL table
.... thanks shahzadfatehali for recent help

I want to format the UL so I can use it in the script for creating accordian menus
http://www.dynamicdrive.com/dynamicindex17/ddaccordion.htm

function createMenu1($parentid) {
 $Result = mysql_query("SELECT * FROM tblcategory WHERE Status=1 and ParentCategoryID = '".$parentid."'");
 $output = '';
 if(mysql_num_rows($Result) > 0){
       $output .= '<ul>';
             while ($Row = mysql_fetch_assoc($Result)) {
              $output .= '<li>'.$Row['CategoryName'];
              $output .= createMenu1($Row['CategoryID']);
              $output .= '</li>';
             }
       $output .= '</ul>';
       }
 mysql_free_result($Result);
 return $output;
}
0
Comment
Question by:joomla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 24783852
Try this
http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu-bullet.htm

and the html generated by above code will work.


0
 

Author Comment

by:joomla
ID: 24784065
Yes, I noticed that link and examined that code they supply for subcategories.

The challenge here is to apply the categoryitems and subcategoryitems to the appropriate UL within the nested loop.

thanks


0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 24784163
PHP function takes care of it. Did you try it?
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:joomla
ID: 24788354
Yes, I tried it
you'll notice in the code within http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu-bullet.htm
it refers to "categoryitems" & "subcategoryitems".
it is specially this which is causig me the trouple
0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 24791613
paste your code and i will modify fix it
0
 

Author Comment

by:joomla
ID: 24799560
Hi shahzadfatehali:
sorry I was unavailable yesterday
I'm don't have any code that actually works

function createMenu1($parentid) {
global $objDB;
$SQL="SELECT * FROM tblcategory WHERE Status=1 and ParentCategoryID = '".$parentid."'";
//echo $SQL; die;
$rs=$objDB->select($SQL);
$output = '';
if(count($rs) > 0){
       $output .= '<ul class="subcategoryitems">';
       for($i=0;$i<count($rs);$i++) {
              $output .= '<li><a href="index1.php?p=cms&CMSID='.$rs[$i]["CMSID"].'" class="subexpandable" >'.$rs[$i]["CategoryName"].'</a>';  
              $output .= createMenu1($rs[$i]['CategoryID']);
              $output .= '</li>';
             }
       $output .= '</ul>';
       }
 return $output;
}

Here is a url in which the top menu cascades properly
http://www.bluelilyclients.com/idh/index1.php?p=accordian

Note that under 'about us' there are a number of submenu with tickmaks
The url also shows the attempted accordion menu
0
 

Author Comment

by:joomla
ID: 24799573
I suspect I have to find a way to correctly identify each li that contains a submenu and not close that li until all children have been crawled
0
 
LVL 9

Expert Comment

by:Shahzad Fateh Ali
ID: 24802396
I guess your problem will be resolved if you replace  class="subcategoryitems" with some unique work or use id instead. You are using same class for all sub <UL>s with make them hidden.
0
 

Accepted Solution

by:
joomla earned 0 total points
ID: 25093711
unfortunately I never did resolve this and have moved on to another task
I'm happy to close this off
thanks for your efforts
Michael
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question