Jump to content

Recommended Posts

Hello everyone, thanks for looking.

 

I have some php code a previous student at Uni developed for a society website, which creates a web-site navigation menu with a list of main menu items. When you click on an item it reveals a sub-menu and then once a sub menu option is clicked on, it then highlights that page you are currently on, on the actual menu itself.

 

The problem I have is that on one web host I use it comes up listing substr_count errors whilst on another it doesn't.

 

Could anyone please advise why this might be and how to resolve this? (The code is below).

 

Thank you in advance for your advice.

 

 

<html>

 

<head>

<LINK rel="stylesheet" type="text/css" href="styles/menuStyles.css">

</head>

 

<body>

 

    <br><br><br><br><br>

<?php

 

class MenuItem {

var $name;

var $url;

var $submenu;

 

function MenuItem($in1,$in2,$in3) {

$this->name=$in1;

$this->url=$in2;

if ($in3=="") {

$this->submenu=FALSE;

} else {

$this->submenu=$in3;

}

}

 

}

 

$menu1= array (

new MenuItem("Page 1","page.php",""),

new MenuItem("Page 2","page.php",""),

new MenuItem("Page 3","page.php",""),

new MenuItem("Page 4","page.php",""),

new MenuItem("Page 5","page.php","")

);

 

$menu2= array (

new MenuItem("Page 1","page.php",""),

new MenuItem("Page 2","page.php",""),

new MenuItem("Page 3","page.php",""),

new MenuItem("Page 4","page.php",""),

new MenuItem("Page 5","page.php","")

);

$menu3= array (

new MenuItem("Page 1","page.php",""),

new MenuItem("Page 2","page.php",""),

new MenuItem("Page 3","page.php",""),

new MenuItem("Page 4","page.php",""),

new MenuItem("Page 5","page.php","")

);

$menu4= array (

new MenuItem("Page 1","page.php",""),

new MenuItem("Page 2","page.php",""),

new MenuItem("Page 3","page.php",""),

new MenuItem("Page 4","page.php",""),

new MenuItem("Page 5","page.php","")

);

 

 

 

// if no menu vales are set - search the menu system

if (!isset($menu) || !isset($submenu)) list($menu,$submenu)=searchmenu(basename($PATH_TRANSLATED));

 

 

function searchmenu($phpfile) {

 

global $mainmenu;

 

$menu=0;

$submenu=0;

 

foreach($mainmenu as $menuitem) {

$menu++;

 

if (substr_count($menuitem->url,$phpfile)) {

$submenu=0;

break(1);

}

 

 

if ($menuitem->submenu) {

global ${$menuitem->submenu};

$submenu=0;

 

foreach (${$menuitem->submenu} as $submenuitem) {

 

$submenu++;

if (substr_count($submenuitem->url,$phpfile)) {

break(2);

}

 

}

 

}

 

}

 

return array($menu,$submenu);

 

}

 

 

 

 

?>

<br/>

<br/><br/><br/>

<table width="160" border="0" cellspacing="0">

 

<?php

 

$t1=1;

foreach ($mainmenu as $menuitem) {

echo "<tr class=\"menubox\">\r\n";

echo "\t<td width=\"10px\" ";

if ($menu==$t1 && $submenu==0) {

echo "class=\"menuselected\"";

} else {

echo "class=\"menuunselected\"";

};

echo ">  </td>\r\n";

 

echo "\t<td colspan=\"2\" width=\"100%\" ";

if ($menu==$t1) {

echo "class=\"menuhighlight\"";

}

 

echo ">\r\n";

echo "\t<a href=\"";

echo $menuitem->url;

if (substr_count($menuitem->url,"?")) {

echo "&";

} else {

echo "?";

}

 

echo "menu=".$t1."\" class=\"menu\">";

echo " ".$menuitem->name;

echo "</a>\r\n";

echo "\t</td>\r\n";

 

echo "</tr>\r\n";

 

if ($menuitem->submenu && $menu==$t1) {

$t2=1;

foreach (${$menuitem->submenu} as $submenuitem) {

echo "\t<tr class=\"menubox\">\r\n";

 

echo "\t\t<td width=\"10px\" ";

echo "class=\"menublank\"";

echo ">  </td>\r\n";

 

echo "\t\t<td width=\"10px\" ";

if ($submenu==$t2) {

echo "class=\"menuselected\"";

} else {

echo "class=\"menuunselected\"";

};

echo ">  </td>\r\n";

 

echo "\t\t<td class=\"menusub\" width=\"100%\">\r\n";

echo "\t\t<a href=\"";

echo $submenuitem->url;

if (!substr_count($submenuitem->url,"?")) {

echo "?";

} else {

echo "&";

}

echo "menu=".$t1."&submenu=".$t2."\" class=\"menu\">";

echo " ".$submenuitem->name;

echo "</a>\r\n";

echo "\t\t</td>\r\n";

 

echo "\t</tr>\r\n";

$t2++;

}

}

$t1++;

}

 

?>

</table>

 

 

 

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/140250-php-menu-script-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.