- $listing_rows = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', 'order by ~always_field~ limit 1000');
- tem_set('listings', $listing_rows);
+ $data = array();
+ $desc = '';
+ $sort = _REQUEST_cut('sort');
+ if ($sort && substr($sort, 0, 1) === '-') {
+ $sort = substr($sort, 1);
+ $desc = ' DESC ';
+ } else {
+ $data["sorting-by-$sort"] = '-';
+ }
+ $legal_sorts = explode(',', ~file_name upper~_DB_FIELDS);
+ if (!$sort || !in_array($sort, $legal_sorts)) {
+ $sort = '~always_field~';
+ }
+
+ $data['rows'] = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', "order by $sort $desc limit 1000");
+ tem_set('listings', $data);