Click to See Complete Forum and Search --> : ORDER BY a column?


gilgalbiblewhee
03-29-2005, 12:13 PM
If I have several fields:
a | b | c | d | e

and the original SQL = SQL & " ORDER BY a ASC ".

I want to place links to b, c, d, e to make the table of results to show by ascending order of b (or , c, d, e).

do I need to place an "if/ end if" in the sql or do I put some statement in the paging?

example
a (ORDER BY a ASC)| b | c | d | e
1 | 3 | z
2 | 2 | y
3 | 1 | x
4 | 5 | w
5 | 4 | v

to

a | b (ORDER BY b ASC)| c | d | e
3 | 1 | x
2 | 2 | y
1 | 3 | z
5 | 4 | v
4 | 5 | w

phpnovice
03-29-2005, 03:34 PM
Create your links with this format:

somepage.asp?order=a

and create a variable something like this:

order = Request.QueryString("order")
If order <> "a" _
And order <> "b" _
And order <> "c" _
And order <> "d" _
And order <> "e" _
Then
order = "a"
End If

and your SQL as follows:

SQL = SQL & " ORDER BY " & order & " ASC "