Sorting data asc and desc using a jump menu
Hello everyone
I have a hard time making this work.. I have some data that i wish to sort by date , and i would like to sort them asc and desc using a jump menu. I know that within the jump menu i have to call 2 queries to the database (asc and desc) but i came to the conclusion that i dont know how to do that. Spam me with your ideas please :)
1 Answer
it will be some thing like this:
<?php // use switch for prevent sql injection switch ($_GET['sort']){ case 'asc': $order = 'ORDER BY `Id` ASC'; break; case 'desc': $order = 'ORDER BY `Id` DESC'; break; } $query = "SELECT * FROM `table`" . $order; // to do it you must use mysql_query() ?> <label for="list">order by:</label> <select onchange="location = '?sort=' + this.options[this.selectedIndex].value;" name="list"> <option selected value="asc">choose...</option> <option value="asc">ASC</option> <option value="desc">DESC</option> </select> <?php echo $query; ?> Posted: MacOS 1 of 1 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved