We have been running ZENCART for over 12 months now without a problem now when selecting certain root categories we get the message:

Fatal error: Call to a member function on a non-object in /hsphere/local/home/jedko/milsims.com.au/test/includes/classes/category_tree.php on line 70

Offending code snippet is:
class category_tree {

function zen_category_tree($product_type = "all") {
global $db, $cPath, $cPath_array;
if ($product_type != 'all') {
$sql = "select type_master_type from " . TABLE_PRODUCT_TYPES . "
where type_master_type = '" . $product_type . "'";
$master_type_result = $db->Execute($sql);
$master_type = $master_type_result->fields['type_master_type'];
}
$this->tree = array();
if ($product_type == 'all') {
$categories_query = "select c.categories_id, cd.categories_name, c.parent_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.parent_id = '0'
and c.categories_id = cd.categories_id
and cd.language_id='" . (int)$_SESSION['languages_id'] . "'
and c.categories_status= '1'
order by sort_order, cd.categories_name";
} else {
$categories_query = "select ptc.category_id as categories_id, cd.categories_name, c.parent_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCT_TYPES_TO_CATEGORY . " ptc
where c.parent_id = '0'
and ptc.category_id = cd.categories_id
and ptc.product_type_id = '" . $master_type . "'
and c.categories_id = ptc.category_id
and cd.language_id='" . (int)$_SESSION['languages_id'] ."'
and c.categories_status= '1'
order by sort_order, cd.categories_name";
}
$categories = $db->Execute($categories_query, '', true, 150);
while (!$categories->EOF) {
$this->tree[$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'],
'parent' => $categories->fields['parent_id'],
'level' => 0,
'path' => $categories->fields['categories_id'],
'next_id' => false);

if (isset($parent_id)) {
$this->tree[$parent_id]['next_id'] = $categories->fields['categories_id'];
}

$parent_id = $categories->fields['categories_id'];

if (!isset($first_element)) {
$first_element = $categories->fields['categories_id'];
}
$categories->MoveNext(); // offending line
}

And the offending line is:

$categories->MoveNext();

My PHP is not that great but I have done some looking around and have establised the following:

1) If I go to the admin module and expand the offending category it looks OK
2) Browsing the category tables look OK

Any help woulfd be much appreciated - thankyou
Jon