Forums

This topic is locked

Changing the order of recordset columns

Posted 27 Jun 2002 16:10:45
1
has voted
27 Jun 2002 16:10:45 S Baldrick posted:
Hi there,

I built a multiple search from a form to display products. Now I would like to be able to change the order of each column just by clicking on the header (eg. name or price). Any ideas? Thanks for your help and time.

Clemens

Any

Replies

Replied 27 Jun 2002 17:29:43
27 Jun 2002 17:29:43 aegis kleais replied:
This is pretty simple.

Do the following:

Make a new record set in SIMPLE MODE. For an example lets say you have a database with a table called tblUsers. Make it select ALL from tblUsers, filtering = nothing and order = ascendingly.

Then hit the ADVANCED button so you'll be editing the SQL Query in advanced mode.

The top hold the Query, then the next area hold variables and the last holds database structure. In the variable area, add 2 blank variables by clicking on the + twice.

In the first variable call it MM_sort, make it's default value the name of your field in the table that you want to sort on if nobody provides a specified field to sort by. Make the runtime for that variable say: Request.QueryString("sort"

In the second variable, make it say MM_order, the default value: ASC, and the runtime = Request.QueryString("order"

Then in the top where it shows the SQL Query, rename it so it says

SELECT *
FROM tblUsers
ORDER BY MM_sort MM_order

Then on your page you have to provide physical links like the following.

<a href="page.asp?sort=fldFirstName&order=DESC">I want to reorder by name descendingly</a>

(However, what I did, is I made a dropdown list of all the table's field names and then a button that says ASC and a button that says DESC. When they select the dropdown, it's value is the name of the field to sort by. Then a javascript handles the page location depending on the dropdown box and the button pressed. Pretty nifty. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle> eh? )
Replied 24 Sep 2007 18:26:57
24 Sep 2007 18:26:57 yasser zohair replied:
I tried this and still doesn't work.. All other variables work (for any column search.. name, date,..etc) except the ORDER BY variable...
Any idea?

Edited by - yazer on 24 Sep 2007 18:28:04

Reply to this topic