The Loop<

admin

Administrator
Staff member
Heres the problem i came accross when making a menu script. i can't figure it out can someone please help me.

<?
$color = "slategray";

$button_string[0] = "1Main,1Sub1,1Sub2,1Sub3";
$button_string[1] = "2Main,2Sub1,2Sub2";
$count_menus = count($button_string);

echo "<SCRIPT for=\"document\" event=\"onclick\">\n";
echo "var menu2=false\n";
echo "if (menu2==false)\n";
echo " {\n";

for ($i=0; $i < $count_menus; $i++)
{
echo "list".$i.".style.display='none'\n";
}

echo "}\n";
echo "</SCRIPT>\n";

echo "<SCRIPT for=\"document\" event=\"onmouseover\">\n";
echo "if (menu==false) \n";

echo " {\n";

for ($i=0; $i < $count_menus; $i++)
{
echo "list".$i.".style.display='none'\n";
}

echo "}\n";
echo "</SCRIPT> \n";

echo "<script language=\"javascript\">\n";
echo "<!--\n";
echo "var menu = false\n";

echo "function show(number,numberhide){\n";
echo "number.style.display=''\n";
echo "numberhide.style.display='none'\n";
echo "}\n";
echo "function hide(){\n";
echo "if(menu==false){\n";

for ($i=0; $i < $count_menus; $i++)
{
echo "list".$i.".style.display='none'\n";
}

echo "}\n";
echo "}\n";
echo "-->\n";
echo "</script>\n";

echo " <table id=\"menutable\" style=\"position:absolute; left:0; top:0\" height=\"20\" cellspacing=\"0\" cellpadding=\"2\" border=\"1\" bordercolor=\"#000080\">\n";
echo " <tr>\n";
echo " <td bgcolor=".$color." width=\"150\" onmouseover=\"show(list$i); menu=true; menu2=true\" style=\"cursor:hand;\" onmouseout=\"menu=false; menu2=false\">\n";
echo " <center>\n";
echo " <font face=\"Verdana\" size=\"2\" color=\"#FFFFFF\"><b>tEXT</b></font>\n";
echo " </center>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";

echo " <td bgcolor=\"".$color."\" width=\"150\" onmouseover=\"show(";
for ($i=0; $i < count_menus; $i++)
{
if ($i = 0)
{
echo "list$i";
}
else{
echo ",list$i";
}
}

echo "); menu=true; menu2=true\" style=\"cursor:hand;\" onmouseout=\"menu=false; menu2=false\">\n";
echo " <table bgcolor=\"".$color."\" style=\"cursor:hand\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo " <table id=\"menutable\" style=\"position:absolute; left:0; top:0\" height=\"20\" cellspacing=\"0\" cellpadding=\"2\" border=\"1\" bordercolor=\"#000080\">\n";
echo " <tr>\n";

echo " <td bgcolor=\"".$color."\" width=\"150\" onmouseover=\"show(";
for ($i=0; $i < count_menus; $i++)
{
if ($i = 0)
{
echo "list$i";
}
else{
echo ",list$i";
}
}
echo "); menu=true; menu2=true\" style=\"cursor:hand;\" onmouseout=\"menu=false; menu2=false\">\n";


echo " <center>\n";
for ($i=0; $i < $count_menus; $i++)
{
echo " <font face=\"Verdana\" size=\"2\" color=\"#FFFFFF\"><b>".$text[0]."</b></font>\n";
}
echo " </center>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";

echo " <td bgcolor=\"".$color."\" width=\"150\" onmouseover=\"show(";
for ($i=0; $i < count_menus; $i++)
{
if ($i = 0)
{
echo "list$i";
}
else{
echo ",list$i";
}
}
echo "); menu=true; menu2=true\" style=\"cursor:hand;\" onmouseout=\"menu=false; menu2=false\">\n";

echo " <table bgcolor=\"".$color."\" style=\"cursor:hand\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";

for ($i=0; $i < $count_menus; $i++)
{
$button = explode(",", $button_string[$i]);

$count_links = count($button);

for ($i=0; $a < $count_links; $i++)
{
echo " <tr>\n";
echo " <td onclick=\"javascript:location.href='http://www.hotmail.com'\" style=\"padding-left: 5px; background-color:".$color."; cursor:hand\" onmouseover=\"this.style.background='cadetblue'\" onmouseout=\"this.style.background='".$color."'\">\n";
echo " <font face=\"Verdana\" size=\"2\" color=\"#FFFFFF\">".$text[$a]."</font>\n";
echo " </td>\n";
echo " </tr>\n";
}
}

echo " </table>\n";
echo " </div>\n";

?>so what is the problem? never mind I found it.

for ($i=0; $a < $count_links; $i++)

that is your last loop. you can't use i as the variable as the loop befor eit uses it. besides where is $a coming from? since it is not set it will loop forever.

so change that loop to this

for ($a=0; $a < $count_links; $a++)

there still is a problem in the code and I am running out of time to look at it. I will do it later if nobody else has fixed it. my guess is you have javascript problems still.In about 3 or 4 of your for loops you have

for( $i=0; $i < count_menus; $i++ )
{
//whatever
}

i beleive you need to have a $ before count_menusheh heh, right u r i picked up the problem earlier this moring but forgot to edit this post :P thx.so blind--angel, did you find out what else was wrong with it.

first where is this being set? $text[]

also event="onclick" and event=\"onmouseover\" are not needed.

then

onmouseover="show(list2); menu=true; menu2=true"

is incorrect as the menu=true is invalid

number.style.display=''
numberhide.style.display='none'

should be

number.style.visibility='visible'
numberhide.style.visibility='hidden'

just some of the errors you have and wasn't sure if you saw these or not. tha tis jsut some of it as it maybe more once you get it actually working.
 
Back
Top