0

I keep getting a error and I can't figure out whats causing it.

An error(8) occurred on line 25. Undefined index: ecount

Line 25 is

$parent_menu[$row->parentId]['ecount']++;

and is apart of this,

if($row->parentId == 0){
			
			$parent_menu[$row->id]['id'] = $row->id;
			$parent_menu[$row->id]['label'] = $row->title;
			$parent_menu[$row->id]['link'] = $row->id;
			$parent_menu[$row->id]['active'] = $row->active;
			$parent_menu[$row->id]['type'] = $row->type;
			$parent_menu[$row->id]['dateMod'] = $row->dateMod;
						
		}else{
		
			$sub_menu[$row->id]['id'] = $row->id;
			$sub_menu[$row->id]['parent'] = $row->parentId;
			$sub_menu[$row->id]['label'] = $row->title;
			$sub_menu[$row->id]['link'] = $row->id;
			$sub_menu[$row->id]['active'] = $row->active;
			$sub_menu[$row->id]['type'] = $row->type;
			$sub_menu[$row->id]['dateMod'] = $row->dateMod;
			$parent_menu[$row->parentId]['ecount']++;
		
		}

Any idea on what is causing this error?

Thanks for your time.
-BaSk

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by tiggsy
0

Did you already declare '$parent_menu' correctly? The error means that there is no 'ecount' unique key in the '$parent_menu' at the location of '$row->parentId'. Check '$parent_menu' with 'var_dump($parent_menu)', and make sure that there is array rooms which are associated with the unique key 'ecount'.

0

It is just a notice.
You can ignore it and stop getting error message by

<?php error_reporting (E_ALL ^ E_NOTICE); ?>
0

How about setting this at the start (before your loop):

$parent_menu[$row->parentId]['ecount'] = 0;

but only if it's supposed to start with 0. Mind you, if you're just using it as a counter, there's no advantage from using this compered to, say, $x.

Like mentioned already, you need to initialize $parent_menu[$row->parentId] before you increment it.

Edited by diafol: n/a

0

If you're trying to assign a value that is one more than the last record to which you assigned a value, then the best way to do this is to store the incrementing value in a global variable such as $recordnumber, and assign it to $parent_menu[$row->parentId].

$recordnumber++;
$parent_menu[$row->parentId]['ecount']=$recordnumber;

don't forget to set global $recordnumber if you're using it inside a function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.