diff --git a/calendar/view.php b/calendar/view.php
index 3931f616c9a..fc3c2d6317d 100644
--- a/calendar/view.php
+++ b/calendar/view.php
@@ -623,7 +623,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $
}
echo ''.$events[$i]->time.'';
echo '
'.$events[$i]->description.'
';
- if($i < $lines - 1) {
+ if($i < $numevents - 1) {
echo '