+ // order by
+ if (!empty($options['sort'])) {
+ $sort_fiels=array();
+ foreach (explode(',', $options['sort']) as $sort_option) {
+ $words = preg_split("/[\s]+/", $sort_option);
+ if (count($words) > 0 && in_array($words[0], array_values($select_fields))) {
+ $tmp = $words[0];
+ if (strtoupper($words[1]) == 'DESC') {
+ $tmp .= " DESC";
+ }
+ $sort_fields[] = $tmp;
+ }
+ }
+ if (count($sort_fields) > 0) {
+ $misc .= " ORDER BY ".implode(",", $sort_fields);
+ }
+ }
+
+ // limit
+ if (!empty($options['limit'])) {
+ ++$param_nr;
+ $misc .= " LIMIT %$param_nr";
+ $query_params[$param_nr] = array($options['limit'], 'Integer');
+ }
+
+ $query = "$select $from $where $misc";