By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,584 Members | 1,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,584 IT Pros & Developers. It's quick & easy.

ascending descending switch

P: n/a
I have been looking at implementing the following but with a difference.

This example uses a link which works with some code shown on the page.

I have a form that is submitted to itself and a drop down list that lets
users select which table field they want to sort by. This is for a form
that selects data from mysql and display a list of results.

For example the select:

<select name="sortby">
<option value="date" <?php if ($sortby == "add_date") { echo
<option value="name" <?php if ($sortby == "stamp_name") { echo
<option value="colour" <?php if ($sortby == "stamp_colour") { echo
<option value="order" <?php if ($sortby == "facevalue_order") { echo

and the select snippet:

"SELECT * FROM table ORDER BY " .$sortby ." ".$dir.";


Now I want to make it so the sort order switches between ascending and
descending without using another drop down list. This is to feed into a
mysql select statement.

Assume the default sort order is ascending (i.e. $dir initially equals
ASC). If the user selects date for a second time the sort order switches
to DESC. If the user switches to $sortby = "name" then sort order will be
ASC. If the user then switches to $sortby ="colour" then sort order will
remain as ASC. Finally if the user chooses $sortby ="colour" for a second
time then sort order will change to DESC.... and so on.

Does anyone have code for this? I had a search and tried some options
(trying to track the history of sortby by pushing it onto an array but it
came unstuck when submitting the form to itself). The above example at
devshed just toggles on every change of the drop down list which isn't
what I want.

Brain no work now - tis late.

Many thanks for any solution.

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.