I have been looking at implementing the following but with a difference.
http://forums.devshed.com/t47653/s.html
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
"SELECTED";}?>>default</option>
<option value="name" <?php if ($sortby == "stamp_name") { echo
"SELECTED";}?>>name</option>
<option value="colour" <?php if ($sortby == "stamp_colour") { echo
"SELECTED";}?>>Colour</option>
<option value="order" <?php if ($sortby == "facevalue_order") { echo
"SELECTED";}?>>value</option>
</select>
and the select snippet:
"SELECT * FROM table ORDER BY " .$sortby ." ".$dir.";
straightforward.
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.
Rene