Have an account? Sign in
Login  Register  Facebook
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 :)
Started: September 17, 2011 Latest Activity: September 17, 2011 php jumpmenu
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
In: September 17, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer