Hi I am trying to create a query that will sort the products display in ASC or DESC depending on the option the user selects from teh drop down. I thought a switch statement would be a good option to achive this so this is how I have tried so far but fail miserable. The switch statment switch ($sortby) { case "ASC": $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'orderby' => 'title', 'order' => 'ASC', 'paged' => get_query_var('paged') ); break; case "DESC": $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'orderby' => 'title', 'order' => 'DESC', 'paged' => get_query_var('paged') ); break; } PHP: The form <form name="myForm"> <select id="sortby"> <option value="ASC">ASC</option> <option value="DESC">DESC</option> <!-- <option value="pc">Postcode</option> --> </select> </form> PHP: Can someone help me out please
what's the problem? i don't get it SELECT * FROM `table` WHERE `title` = 'hello world' ORDER BY `id` DESC EDITED: on a second look, change id="sortby" to name="sortby"
Hi this is what i am trying to achieve the clause WHERE= $variable bacause the drop down will be coming froma drop down. // get the post from the form (sortbyexpiry) and change the switch depending on the form value see form bellow switch ($_POST['location']) { case "location": echo "<h3>location: $variable </h3>"; $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'WHERE' => ' $variable', 'paged' => 'paged' ); break; } PHP:
$variable = isset($_POST['sortby']) ? ($_POST['sortby'] == "DESC" ? "DESC" : "ASC") : "DESC"; is that it?