I have 2 codes that do the same task. 2.In the long code $sort = 'newest';
I'm throwing the variable. But in the 1st shortcode I don't know how to assign it.
*The code to be edited is the 1st Code. (Short Code)
Short IF PHP Code
$sql_code_orderby = ( $sort == 'oldest' ? "ORDER BY Q.created ASC" : ($sort == 'votes' || ($sort == '' && $filter == 'noanswers')) ? "ORDER BY Q.vote_count DESC" : ($sort == 'viewed' ? "ORDER BY Q.viewed DESC" : "ORDER BY Q.created DESC" ) );
Long IF PHP Code
if( $sort == 'oldest' ){
$sql_code_orderby = "ORDER BY Q.created ASC";
} else if( $sort == 'votes' || ($sort == '' && $filter == 'noanswers') ){
$sql_code_orderby = "ORDER BY Q.vote_count DESC";
} else if( $sort == 'viewed' ){
$sql_code_orderby = "ORDER BY Q.viewed DESC";
} else {
$sort = 'newest';
$sql_code_orderby = "ORDER BY Q.created DESC";
}
My fault trial result:
$sql_code_orderby = ( $sort == 'oldest' ? "ORDER BY Q.created ASC" : ($sort == 'votes' || ($sort == '' && $filter == 'noanswers')) ? "ORDER BY Q.vote_count DESC" : ($sort == 'viewed' ? "ORDER BY Q.viewed DESC" : "ORDER BY Q.created DESC" . ($sort = 'newest') ) );
My Answer:
'ORDER BY date ASC' : 'ORDER BY date DESC');Long IF PHP Code$sort = 'newest';$sql_code_orderby = '';if ($sort == 'oldest') {
$sql_code_orderby = 'ORDER BY date ASC';
} else {
$sql_code_orderby = 'ORDER BY date DESC';
}
Rate this post
5 of 5 based on 9828 votesComments