I have been developing a small site and i have done mostly everything reading through forums, but i can't seem to find a solution for the problem i have,
Trying to create a dynamic menu system using the following structure below from a pre-existing database i have been working from.
Ultimately i want a drop down menu system but i want it to be created automatically through loop statements?
CATEGORY_ID NAME
1 Cameras
2 Cameras>Camera Heads
3 Cameras>Camera Heads>SD
4 Cameras>Camera Heads>HD
5 Cameras>Camcorders
6 Cameras>Camcorders>SD
7 Cameras>Camcorders>HD
8 Camera Accessories
9 Camera Accessories>Matte Boxes
13 Lenses
14 Lenses>Broadcast
15 Lenses>Broadcast>SD
16 Lenses>Broadcast>HD
17 Lenses>Professional
18 Lenses>Professional>Specialist
19 Lenses>Adaptors
20 Lenses>Converters
21 Lenses>Controls
22 Lenses>Follow Focus
etc..
This is the code i have been using, been trying for a few days to get it to work:
function gen($id)
{
if(isset($id))
{
print_r($id);
}else{
continue;
}
}
function rentalmenu_Generator()
{
include('oracleonnect.php');
$query = oci_parse($conn,"SELECT HIRE_CATEGORY.* FROM WEBEQUIPMENT.HIRE_CATEGORY ORDER BY NAME");
ociexecute($query);
echo "<div id='container'>";
echo "<div id='content'>";
echo "<div class='menu-nav'>";
$call = array();
$i = 0;
while ($row = oci_fetch_array($query, OCI_BOTH))
{
$catid = $row['CATEGORY_ID'];
$menuname = $row['NAME'];
$strip = explode(">", $menuname);
//$toplevel = $name;
//if (strpos($menuname,">")===false)
//{
//$toplevel = $menuname;
//}else{
//$submenu = explode(">", $menuname);
//}
//echo $toplevel;
//echo "<br />";
$test = count($strip, COUNT_RECURSIVE);
//$max = max($strip);
//echo $max;
if ($test == 1)
{
$toplevel = $strip[0];
echo "<ul><li class='start'><a href='".$_SERVER['PHP_SELF']."?cat=".$catid."'>".$toplevel."</a></li></ul>";
$parents[] = $toplevel;
}else{
$toplevel2 = $strip[1];
echo "<li class='sub'><a href='".$_SERVER['PHP_SELF']."?cat=".$catid."'>".$toplevel2."</a>";
$submenu1[] = $toplevel2;
$call[$toplevel] = $toplevel2;
if (isset($strip[2]))
{
$toplevel1 = $strip[2];
echo "--><a href='".$_SERVER['PHP_SELF']."?cat=".$catid."'>".$toplevel1."</a></li>";
$submenu2[] = $toplevel1 ;
$call[$toplevel] = $toplevel1;
}else{
echo "</li>";
}
gen($call);
}
$i++;
//echo $i;
}
//print_r($call);
$num_rows = oci_num_rows($query);
$maxrecords = $num_rows;
$countparents = count($parents);
echo "<br />";echo "<br />";echo "<br />";echo "<br />";
$t = 0;
while($countparents < $maxrecords )
{
if(isset($parents[$t]))
{
echo $parents[$t];
$sub = 0;
if(isset($submenu1[$sub]))
{
while($submenu1[$sub])
{
echo "<br />";
echo "-->".$submenu1[$sub];
$sub++;
continue 1;
}
}
echo "<br />";
}else{
break;
}
$t++;
$countparents++;
}
//print_r($parents);
//print_r($submenu1);
echo "<br />";
echo "</div>";
echo "</div>";
echo "</div>";
ocifreestatement($query);
oci_close($conn);
}
The Outout i am trying to achieve:
<ul>
<li class="parent">Cameras</li>
<ul>
<li class="child">Camera Heads</li>
<ul>
<li class="subchild">SD</li>
<li>HD</li>
</ul>
<li class="child">Camcorders</li>
<ul>
<li class="subchild">SD</li>
<li class="subchild">HD</li>
</ul>
</ul>
etc....
</ul>
Hopefully this will make sense to someone?