Fixing another postgres problem. With distinct, you can't order by a field not in the select field list

This commit is contained in:
mjollnir_
2005-08-25 00:02:49 +00:00
parent cef4a0e828
commit 289cf90737
+7 -2
View File
@@ -2129,8 +2129,13 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
$selectsql = "{$CFG->prefix}course c $teachertable";
}
return get_records_sql("SELECT ".((!empty($teachertable)) ? " DISTINCT " : "")." $fields FROM $selectsql ".((!empty($sort)) ? "ORDER BY $sort" : ""));
$extrafield = str_replace('ASC','',$sort);
$extrafield = str_replace('DESC','',$extrafield);
$extrafield = trim($extrafield);
if (!empty($extrafield)) {
$extrafield = ','.$extrafield;
}
return get_records_sql("SELECT ".((!empty($teachertable)) ? " DISTINCT " : "")." $fields $extrafield FROM $selectsql ".((!empty($sort)) ? "ORDER BY $sort" : ""));
}