Using PHP Order By to sort query results -
the below code displays data table , filters depending on results of 2 combo boxes. able order results id once form submitted, not on initial load (where listed). have tried $sql = "select * places order id";
works when list loads returns error when form submitted. hope makes sense. ideas? thanks!
// default query $sql = "select * places"; // check if form submitted if (isset($_post['area'])) { $connector = 'where'; if ($_post['area'] != 'all') { $sql .= " area = '".$_post['area']."' order id"; $connector = 'and'; } if ($_post['theme'] != 'all') { $sql .= " $connector theme = '".$_post['theme']."' or theme2 = '".$_post['theme']."' order id"; } }
your order id
clause must appear @ end of statement. if both $_post['area']
, $_post['theme']
filled, end query this:
select ... area = 'some area' order id , theme = 'some theme'
add order by
bit last part of query.
Comments
Post a Comment