Permalink
Browse files

Prevent 'Warning: Invalid argument supplied for foreach() in ...' for…

… get_courses_page function when there are no courses in the required category.
  • Loading branch information...
1 parent b471331 commit 12490fc2b32f750220e510a0e4f5201a76b71826 dwoolhead committed Sep 22, 2006
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/datalib.php
View
@@ -576,11 +576,13 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
}
// pull out all course matching the cat
- $courses = get_records_sql("SELECT $fields
+ $visiblecourses = array();
+ if (!($courses = get_records_sql("SELECT $fields
FROM {$CFG->prefix}course c
$categoryselect
- ORDER BY $sort");
- $visiblecourses = array();
+ ORDER BY $sort"))) {
+ return $visiblecourses;
+ }
$totalcount = 0;
if (!$limitnum) {
@@ -1515,4 +1517,4 @@ function category_parent_visible($parent = 0) {
}
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
-?>
+?>

0 comments on commit 12490fc

Please sign in to comment.