find this line:
$SQL = "SELECT ID FROM schedule WHERE year='$thisyear' AND month='$thismonth' AND day='$thisday' AND hour='$hour'";
and change to:
$SQL = "SELECT ID FROM schedule WHERE year='$thisyear' AND month='$thismonth' AND day='$thisday' AND hour='$hour' and status='Queued'";