Is this what you're looking for?
$fromsite = $dataConnection->SelectAllWhere(
"applicants",
"loan_purpose='VA Streamline' AND statusdate >= '3/1/2011'",
"ORDER BY fromsite " . ( $isAscending ? 'ASC' : 'DESC' )
);
I'm assuming you have some value (maybe a $_GET
parameter) to decide whether to sort ascending or descending. If $isAscending
evaluates to true
, the query will sort ascending, otherwise descending.
What I used there is called the ternary operator (?:
). You can find it on the PHP comparison operators page (http://php.net/manual/en/language.operators.comparison.php).
EDIT: Assigning $isAscending
will differ depending on the input passed in... but here are some examples.
Checkbox - checked is ascending, unchecked is descending
$isAscending = isset( $_REQUEST['input_name'] ) ? true : false;
Checkbox - checked is descending, unchecked is ascending
$isAscending = isset( $_REQUEST['input_name'] ) ? false : true;
Select drop down - values ASC
, DESC
$isAscending = $_REQUEST['input_name'] == 'ASC' ? true : false;
Select drop down - 0 is ascending, 1 is descending
$isAscending = $_REQUEST['input_name'] == 0 ? true : false;