1

The following code throws an error (Highlighted below)

Notice: Undefined offset: 0 in C:\Program Files (x86)\Zend\Apache2\htdocs\module\news.php on line 95 Notice: Undefined offset: 0 in C:\Program Files (x86)\Zend\Apache2\htdocs\module\news.php on line 96 Notice: Undefined offset: 0 in C:\Program Files (x86)\Zend\Apache2\htdocs\module\news.php on line 99 Notice: Undefined offset: 0 in C:\Program Files (x86)\Zend\Apache2\htdocs\module\news.php on line 100

Can someone point me in the right direction, please.

    {
        $i = 0
        $commentData[$a] = array($row['id'],$row['text'],$row['author'],$row['time']);
        $a++;
    }
    $_GET['page'] = (int)$_GET['page'];
    if(!isset($_GET['page'])) $_GET['page'] = 1;
        for($i = (($_GET['page'] - 1) * 10); $i < (($_GET['page']) * 10);$i++)
        {
            LINE 95 >> $nCommentID = $commentData[$i][0];
            LINE 96 >> $szText = $commentData[$i][1];
            $szText = misc::applyAttributesToText($szText);
            $szText = security::fromHTML($szText);
            LINE 99 >> $szAuthor = $commentData[$i][2];
            LINE 100 >> $szTime = $commentData[$i][3];

Thank you.

Tony

1 Answers1

0

You didn't include the complete code that fills your $commentData, but you seem to have a loop filling it with values, and then calling it in another loop. Somewhere you call a value that hasn't been set, which is certainly possible, but hard to say whay without the first loops definition.

The error means that

$commentData[$i][0];

was not set. So debug by echoing all the $a in your first loop, and all the $i in the second loop, and I'm sure the second loop will contain values that your first loop doesn't. And then you're looking at an undefined $commentData[$i], so obviously the $commentData[$i][0] will be an undefined offset.

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • (same goes for `[1]` on the next line of course) – Nanne Apr 20 '14 at 07:21
  • Sorry. I should have mentioned I'm a noob (Obvious, I'm sure), with little experience with PHP. Just trying to fix issues with our new page that keep cropping up. :-( The top code follows: $commentData = array(); $a = 0; while($row = mssql_fetch_array($hGetComments)) { $commentData[$a] = array($row['id'],$row['text'],$row['author'],$row['time']); $a++; } – user3553376 Apr 20 '14 at 08:36
  • The point stays. You check an array value that is never set. Did you even try the debug - hint I gave you? Echo the parts of the array you set, and check if you limit yourself to those, and not try to read others. If try try to read an array value that has never been set, PHP warns you about it with a notice. – Nanne Apr 21 '14 at 07:49