Well, I had this working, but I think I'm goofed something up, so much so that now nothing shows up. :sigh:
Here's the code for the pages affected. See what you can dig up.
menu.php:
<?php
//local connection
$dblink= mysql_connect("localhost", "username", "password")
or die("Could not connect: " . mysql_error());
mysql_select_db("database",$dblink);
class main_menu{
var $menu;
var $track;
var $cat_id;
function main_menu(){
$this->menu=array();
$this->track=array();
$this->cat_id=NULL;
}
//this function loops through all of the children of the menu
function get_children($dblink, $value, &$level, &$tmpmenu){
$query = "SELECT * FROM navigation WHERE parent='".$value."' AND active=y ORDER BY title;";
if($result=mysql_query($query,$dblink)){
$level++;
if(mysql_num_rows($result)>0){
$i=0;
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
$tmpmenu->sub_menu[$i]=new menu_item($row['title'],$row['path'],$row['id'],$row['parent']); //make sure to change this line to match you links.
$this->get_children($dblink,$row['id'],$level,$tmpmenu->sub_menu[$i]);
$i++;
}
$level--;
return 1;
} else {
$level--;
return 0;
}
}
return 0;
}
//print out the menu for testing
function print_menu($tmpmenu,&$level){
$level++;
for($i=0; $i<count($tmpmenu); $i++){
echo str_repeat('•',$level).$i.':title:'.$tmpmenu[$i]->title.' (url:'.$tmpmenu[$i]->url.')<br />';
$this->print_menu($tmpmenu[$i]->sub_menu,$level);
}
$level--;
return;
}
function display_menu($dblink){
//init and build the menu from the category db
$level=0;
$this->menu[0]=new menu_item('Products','category.php',0,0);
$this->get_children($dblink,0,$level,$this->menu[0]);
//determine the position of the currently selected menu item
$level=0;
$this->get_menu_track($this->menu[0]->sub_menu,$level);
//create an html version of the menu for output
$field='';
$level=0;
$this->prepare_menu($this->menu[0]->sub_menu,$level,$field);
return $field;
}
//this function loops through the menu looking to see what is the currently selected item, based on this->cat_id.
function get_menu_track($tmpmenu,&$level){
$level++;
for($i=0; $i<count($tmpmenu); $i++){
if($this->cat_id==$tmpmenu[$i]->id){
$this->track[$level]['menu_pos']=$i;
$this->track[$level]['id']=$tmpmenu[$i]->id;
$this->track[$level]['title']=$tmpmenu[$i]->title;
$this->track[$level]['url']=$tmpmenu[$i]->url;
$level--;
return true;
} else {
if($this->get_menu_track($tmpmenu[$i]->sub_menu,$level)==true){
$this->track[$level]['menu_pos']=$i;
$this->track[$level]['id']=$tmpmenu[$i]->id;
$this->track[$level]['title']=$tmpmenu[$i]->title;
$this->track[$level]['url']=$tmpmenu[$i]->url;
$level--;
return true;
}
}
}
$level--;
return false;
}
//loops through all the menu items and adds html formatting to make them look nice.
function prepare_menu($tmpmenu,&$level,&$field){
$level++;
for($i=0; $i<count($tmpmenu); $i++){
if($tmpmenu[$i]->id==$this->cat_id){
//this is the currently selected menu item, you can change this to not be a link
$field.=str_repeat(' ',($level-1)).'• <a href="'.$tmpmenu[$i]->url.'">'.$tmpmenu[$i]->title.'</a><br />';
} else{
$field.=str_repeat(' ',($level-1)).'• <a href="'.$tmpmenu[$i]->url.'">'.$tmpmenu[$i]->title.'</a><br />';
}
if(isset($this->track[$level]['menu_pos']) && $this->track[$level]['menu_pos']==$i){
$this->prepare_menu($tmpmenu[$i]->sub_menu,$level,$field);
}
}
$level--;
return;
}
}
class menu_item{
var $id;
var $parent;
var $title;
var $url;
var $sub_menu;
function menu_item($tmptitle,$tmplink,$tmpid,$tmpparent_id)
{
$this->id=$tmpid;
$this->parent=$tmpparent_id;
$this->title=$tmptitle;
$this->url=$tmplink;
$this->sub_menu=array();
}
}
?>
left_column_content.php (where menu will display):
<?php
//error_reporting(E_ALL ^ E_NOTICE);
include('includes/menu.php');
$tmpmenu = new main_menu();
$tmpmenu->cat_id=$_GET['cat_id'];
//$tmpmenu->display_menu($dblink);
?>
<BR>
<table width="144" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign="bottom">
<td width="144" colspan="3"><img src="images/tableleft_top.jpg" width="144" height="9"></td>
</tr>
<tr valign="top">
<td width="1" background="images/pixel_gray.jpg"><img src="images/pixel_gray.jpg" width="1" height="1"></td>
<td width="142"><table width="140" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="style3"> <div align="center"></div> <table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<div align="center">Case Studies<br>
<br>
Brochure<br>
<br>
Search
</div></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="1" background="images/pixel_gray.jpg"><img src="images/pixel_gray.jpg" width="1" height="1"></td>
</tr>
<tr valign="top">
<td colspan="3" width="144"><img src="images/tableleft_bottom.jpg"></td>
</tr>
</table>
<BR>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<?php
print_r($tmpmenu);
echo $tmpmenu->display_menu($dblink);
?>
</td>
</tr>
</table>
index1.php (a sample page for test purposes):
<?php
include('display.php');
head();
?>
<table width="562" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/main.gif" width="563" height="249"></td>
</tr>
</table>
<? horizontal(); ?>
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><div align="center">
<?php include "tinytable_main1.php"; ?>
</div></td>
<td valign="top"><div align="center">
<?php include "tinytable_main2.php"; ?>
</div></td>
<td valign="top"><div align="center">
<?php include "tinytable_main3.php"; ?>
</div></td>
<td valign="top"><div align="center">
<?php include "tinytable_main4.php"; ?>
</div></td>
</tr>
</table>
<br>
<?php
foot();
?>