change it to:
<?php
$date = date("Ymd", time()+3600*7);
$NumEvents = 0;
$handle = opendir('../event_dates');
$inc_files = array();
while (($file = readdir($handle)) !== false) {
if ($file >= $date) {
$inc_files[] = $file;
}
}
$NumEvents = count($inc_files);
if ($NumEvents > 0) {
sort($inc_files);
for ($i = 0; $i < $NumEvents; $i++) {
include '../event_dates/' . $inc_files[$i];
}
echo $NumEvents . " events are scheduled";
}
else {
echo "<strong class='red'>Sorry, no events are planned at present</strong>";
}
?>
the reason would be that:
$file >= $date
returns false, so $inc_files is never initialised.
Here we explicitly initialise it, then test for $NumEvents
Notice that I've removed the $NumEvents++ in the for loop, as it isnt necessary.
Rather, I assigned count($inc_files) to $NumEvents, as that would be the result of the incrementing.
This also takes the function out of the loop condition, which optimises the loop.
I would suggest using $num_events instead, to maintain a consistent variable naming scheme.
Then use CONSTANT_NAME for constants, functionName() for function names, and ClassName for class names.
Incidentally, instead of the for loop, you could also use:
foreach ($inc_files as $inc_file)
include '../event_dates/' . $inc_file;