Hi,
I have three tables in a MySQL database.
- collection
- category
- subcategory
I use the following function to retrieve data from these tables to display as a tree:
function create_menu($params)
{
//retrieve menu items
//get collection
$collection = get('xxcollection') ;
foreach($collection as $c)
{
echo '<div class="parent" style="direction:rtl">';
echo '<img src="../images/dtree/minus.gif" align="absmiddle" class="parent_item" id="minus" />
<img src="../images/dtree/base.gif" align="absmiddle" id="base">
'.$c['xcollectionname'] ;
//get categories
$cat = get_where('xxcategory' , array('xcollectionid'=>$c['xcollectionid'])) ;
foreach($cat as $item)
{
echo '<div class="node" >';
echo '<img src="../images/dtree/plus.gif" align="absmiddle" class="node_item" id="plus" />
<img src="../images/dtree/folder.gif" align="absmiddle" id="folder">
'.$item['xcatname'] ;
$subcat = get_where('xxsubcategory' , array('xcatid'=>$item['xcatid'])) ;
foreach($subcat as $val)
{
echo '<div class="sub_node" style="display:none">' ;
echo '<img src="../images/dtree/join.gif" align="absmiddle" style="padding-left:2px;" />
<a id="'.$val['xsubcatid'].'" href="javascript:void(0)" onclick="getProduct(this , event)" class="sub_node_links" >
'.$val['xsubcatname'].'</a>';
echo '</div>';
}
echo '</div>';
}
echo '</div>';
}
}
- How can I determine the first and last iteration in the foreach loop?
- Is it the correct way to retrieve data to be displayed as a tree?
- I know it's not standard to use
<div>
tag to display a tree-like menu. I prefer to use nested<ul>
s. However, I always have problems with<ul>
in IE. I hope to get some advices or resources on how to use<ul>
tags which work in different web browsers.