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

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'.

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

<?php error_reporting (E_ALL ^ E_NOTICE); ?>
Member Avatar for diafol

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.