473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ascending descending switch

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
Jul 17 '05 #1
0 4071

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Seansan | last post by:
Hi there, I am trying to sort an array hash on values. I pass a FORM tag and resolve it to the array position to sort on. (see code below). Is there an easy way to sort ascending or descending...
1
by: AwanJohnie | last post by:
I have an XML doc and successfully transformed into a table using XSL. The Challenge is how to sort the information by columns. I am writting diffrent XSL for the diffrent sorts (i.e per column)...
1
by: Rich N | last post by:
When I open my form, I want the records already in it to be in Ascending Order based on one field. Though I keep putting them in Ascending order and then saving the form, each time I re-open the...
0
by: Alex | last post by:
I found some good information On "Ascending and Descending Sorting of Columns in an ASP.NET DataGrid..." at this site http://www.dedicatedsolutions.co.uk/DesktopDefault.aspx?tabid=62 It is worth...
2
by: Steve Chatham | last post by:
How do you make a sort work in ascending & descending order on the column in a datagrid. I have it now where it'll return the numbers from lowest to highest. SC
2
by: Joe | last post by:
Hi, I have an asp.net script that connects to MS Access database and displays data in a table. For some reason I am do not know how to display data say in ascending order of column1. I have...
1
by: Mark | last post by:
Rather than have only one column sorted in a single direction in a listview. I would like to be able to sort on any column in alternating directions (ascending,descending) eg. First column click...
1
by: Richard | last post by:
The obvious way to do it is ListView1.Sorting = SortOrder.Ascending 'or SortOrder.Descending But, I've made my own IComparer, cause it shall sort in a different way, and then the above...
11
by: dwelden | last post by:
I have successfully used the sort lambda construct described in http://mail.python.org/pipermail/python-list/2006-April/377443.html. However, how do I take it one step further such that some values...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.