Syntax Error T Enforeach

We have just taken over a website and for some reason getting this error, but not sure why? Can anyone see with the code below:

Parse error : syntax error, unexpected ‘endforeach’ (T_ENDFOREACH) in etc…

<?php foreach($results as $entry):  ?>
<?php if (!empty($lastCat) && $lastCat!=$entry->cat):?>
<tr class="match-spacer"><td colspan="4">&nbsp;</td></tr>
<?endif;?>
<tr>
    <td class="group-<?php echo $entry->cat; ?>"><?php echo $entry->peg; ?></td>
    <td><?php echo $entry->name; ?></td>
    <td><?php echo $entry->weight; ?></td>
    <td><?php echo ceil($entry->score); ?></td>
</tr>
<?php $lastCat=$entry->cat; endforeach; ?>

Should be

<?php endif;?>

Sponsor our Newsletter | Privacy Policy | Terms of Service