I have taken snippets of various code I have found/done and come up with this code to generate a menu:
<?
class submenu {
var $urls;
var $desps;
var $cot;
var $id;
function create($id) {
$this->cot=0;
$this->id=$id;
}
function add($url, $desp) {
$this->urls[$this->cot]=$url;
$this->desps[$this->cot]=$desp;
$this->cot++;
}
function open() {
$i=0;
echo '<table width="150" border="0" align="center">';
while($i<=$this->cot) {
if ($i==0) { / ±íÍ· /
echo '<tr><th align="center" bgcolor="#34ABC0"><font color="White">';
echo $this->desps[0];
echo '</font></th></tr>';
}
else {
echo '<tr><td align="center" ><font size="-1">';
echo '<a href="'.$this->urls[$i].'">'.$this->desps[$i].'</a>';
echo '</font></td></tr>';
}
$i++;
}
echo '</table>';
}
function close() {
echo '<table width="150" border="0" align="center">';
echo '<tr><th align="center" bgcolor="#34ABC0"><font color="White">';
echo '<a href="?action=open&id='.$this->id.'">'.$this->desps[0].'</a>';
echo '</font></th></tr>';
echo '</table>';
}
}
class menu {
var $submenus;
var $cot;
var $id;
function create() {
$this->cot=0;
$this->id=1;
}
function add($submenu) {
$this->submenus[$this->cot]=new submenu;
$this->submenus[$this->cot]=$submenu;
$this->cot++;
}
function show() {
$i=0;
$tmp = new submenu;
while ($i<$this->cot) {
$tmp=$this->submenus[$i];
if ($tmp->id==(string)$this->id) {
$tmp->open();
}
else {
$tmp->close();
}
$i++;
}
}
}
$sm_1=new submenu;
$sm_1->create('1');
$sm_1->add('','Menu 1');
$sm_1->add('link.php','Link 1');
$sm_1->add('link.php','Link 2');
$sm_2=new submenu;
$sm_2->create('2');
$sm_2->add('','Menu 2');
$sm_2->add('link.php','Link 1');
$sm_2->add('link.php','Link 2');
$m_1=new menu;
$m_1->create();
$m_1->add($sm_1);
$m_1->add($sm_2);
if ($action=='') {
$m_1->show();
}
if ($action=='open') {
$m_1->id=$id;
$m_1->show();
}
?>
*** My problem is that when you click on one of the submenu items it goes to the link but restores the table back to it's original display (with subcat 1 open) I want it to be able to stay on where it was when the link was clicked.