Undefined offset error

I’m getting an error “Undefined offset: 10 in C:\xampp\htdocs(…)\index.html on line 55”. Which is on the first line of my for loop.

This is the code:

[php]
for($i=1;$Page[$i][0];$i++){
if($i!=1){echo “\n <img src=”./Images/leftmenu_line1_ver2.jpg" alt="" />";}
echo “<div class=“leftmenu_txt”><a style=“color: “;
if(($Pagenum1==$i)&&($Pagenum2==0)){echo “#B82647”;}else{echo “#333333”;}
echo “” href=”./index.html?Pagenum=”.$i.“0”>”.$Page[$i][0]."";
if( ($Pagenum1==$i) ){
for($j=1;$Page[$i][$j];$j++){
echo “\n <img src=”./Images/leftmenu_line2_ver2.jpg" alt="" />";
echo “<div class=“leftmenu_subtxt”><a style=“color: “;
if($Pagenum2==$j){echo “#B82647”;}else{echo “#333333”;}
echo “” href=”./index.html?Pagenum=”.$i.$j.”">".$Page[$i][$j]."";
if(($i==1)&&($j==2)){echo “
”;}
}
}
}
[/php]

The array is defined before:

[php]<?php
$Page=array();
$Page[1][0]=“A”;
$Page[1][1]=“B”;
$Page[1][2]=“C”;
$Page[2][0]=“D”;
$Page[2][1]=“E”;
$Page[2][2]=“F”;
$Page[2][3]=“G”;
$Page[3][0]=“H”;
$Page[4][0]=“I”;
$Page[4][1]=“J”;
$Page[4][2]=“K”;
$Page[4][3]=“L”;
$Page[4][4]=“M”;
$Page[4][5]=“N”;
$Page[5][0]=“O”;
$Page[5][1]=“P”;
$Page[5][2]=“Q”;
$Page[5][3]=“R”;
$Page[5][4]=“S”;
$Page[5][5]=“T”;
$Page[6][0]=“U”;
$Page[6][1]=“V”;
$Page[6][2]=“W”;
$Page[7][0]=“X”;
$Page[8][0]=“Y”;
$Page[9][0]=“Z”;
$Page[0][0]=“NUMISHEET 2011”;
?>[/php]

The problem is that you are trying to use a character where php is expecting a number.

Given your array, what you are saying with your if statement is…

Set $i = 1. While $i is less than the letter “A” do this stuff. Each iteration, add 1 to $i.

I couldn’t quite figure out what you were going for based on the code you posted, so I’m not quite sure what to recommend. If you could explain the array structure and what you are looking to do with your for loop, I would be happy to assist you with whatever changes are needed.

there is no number 10 when you are counting the index’s for the page it goes only to 9, so when it counts to 10 it has a 0 instead of 10.

[php]$Page[$i][0];

$Page[9][0]=“Z”;
$Page[0][0]=“NUMISHEET 2011”;[/php]

What I am doing is assigning names to each of the $Page components, so when I build a left menu, the menu items are as assigned. To each one I have an .html file linked.

But then when I add a $Page[10][0], it will result in “Undefined offset: 11 in C:\xampp\htdocs(…)\index.html on line 55”.

It will keep looking for further indexes? How can I stop it from looking for further indexes when there are no more available?

Mariana,

I think I am seeing what you are looking to do. This probably won’t take care of everything, but see if this gets you in the ballpark…[php]for($i=1;$i<count($Page);$i++)
{
if($i!=1)
{
echo “\n”;
}
echo "

<a style='color: ";
if(($Pagenum1==$i)&&($Pagenum2==0))
  {
    echo "#B82647";
  }
else
  {
    echo "#333333";
  }

echo "' href='./index.html?Pagenum=".$i."0'>".$Page[$i][0]."</a></div>";

if(($Pagenum1==$i))
  {
    for($j=0;$j<count($Page[$i]);$j++)
      {
        echo "\n<img src='./Images/leftmenu_line2_ver2.jpg' alt='' />";
        echo "<div class='leftmenu_subtxt'><a style='color: ";
        if($Pagenum2==$j)
          {
            echo "#B82647";
          }
        else
          {
            echo "#333333";
          }
        echo "' href='./index.html?Pagenum=".$Page[$i][$j]."'>".$Page[$i][$j]."</a></div>";
        if(($i==1)&&($j==2))
          {
            echo "<br>";
          }
      }
  }

}[/php]

I have no doubt that this will need to be adjusted to make it work the way you want, but it might get you on the right track.

jay

Thanks Malasho! The notice is finally gone. :wink:

Glad it worked for you!

Best,

jay

Sponsor our Newsletter | Privacy Policy | Terms of Service