From: dwoolhead Date: Fri, 22 Sep 2006 11:15:10 +0000 (+0000) Subject: Prevent 'Warning: Invalid argument supplied for foreach() in ...' for get_courses_pag... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=12490fc2b32f750220e510a0e4f5201a76b71826;p=moodle.git Prevent 'Warning: Invalid argument supplied for foreach() in ...' for get_courses_page function when there are no courses in the required category. --- diff --git a/lib/datalib.php b/lib/datalib.php index e31fb02729..e3b59c0b03 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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: -?> +?> \ No newline at end of file