Link to home
Start Free TrialLog in
Avatar of prettykittyq
prettykittyq

asked on

Re-sort a table by user-selected variable

I'm using an Access 2000 db as the data source for a table on a web page that's generated with ASP.

The table looks like:

Project Name       Coordinator      Product
Project X             Kitty                  Rule
Project Me           Bear                 Rule
Nuke 'Em            Kitty                   Lawsuit

When the page appears the first time, the projects are sorted by project name.
I'd like to be able to allow the user to click on the column heading (which is also the field name) to re-sort the output by that field.

I've been trying to get this to work by setting the column names up as:

<a href=showprojects.asp?pickorder=Coordinator>Coordinator</a>

thinking that a click on that link should set the variable pickorder equal to the desired field name.

The asp code then says:

pickorder=request("pickorder")
strsql="SELECT * from tblProjects ORDER BY '" & pickorder & "'"

When I click on a link, the URL indicates "it" understands that pickorder is equal to Coordinator but it doesn't re-sort the data.

What am I doing wrong?

If you need more code, just ask.  I'm a newbie so I don't know when enough is too much and I thought I'd spared you digging through a bunch of irrelevant stuff.

Thanks in advance.

Kitty
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prettykittyq
prettykittyq

ASKER

Trying it out.  Be right back.

Kitty
I get a line at the top of the page that says:

SELECT * from tblProjects ORDER BY 'ProjectName'

Should I not have put the single quotes in there?
Fritz, you are brilliant!

I got rid of the single quotes and it now works.

Thanks a whole bunch.  That was driving me crazy.

Cheers!

Kitty
Glad to have helped.

Whenever things don't work the way that you expect, use a response.write followed by a response.end to figure out what is happening.

Good luck with your project,

FtB
As an aside, you need the delimiters for where something ='something' when that something is text or date. You also need it for insert clauses for text and date values, but not for order by clauses.

FtB