Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Another easy one... SQL & ORDER BY
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Another easy one... SQL & ORDER BY

 Post Reply Post Reply
Author
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Topic: Another easy one... SQL & ORDER BY
    Posted: 16 July 2003 at 2:27pm

i have a page that displays the records in a table from a db. How do i go about making a link that when clicked, will sort the data displayed by a certain column, in Ascending and Descending order.

If no one wants to answer this, can someone at least point me to a tutorial?

Thanks.

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 16 July 2003 at 7:27pm

It is fairly easy to do.
<%
Dim strSortOrder
strSortOrder = Request.QueryString("so")
If strSortOrder = "" THEN
 strSortOrder = "asc"
END IF
'Your connection suff
strSQL = "Select * from yourtable order by yourfiled " & strSortOrder
'Execution Stuff
.......
If strSortOrder = "asc" THEN
Response.Write "<td><a href=""thispage.asp?so=desc"">Column to be sorted by</a></td>"
ELSE
Response.Write "<td><a href=""thispage.asp?so=asc"">Column to be sorted by</a></td>"
END IF
....


That should give you an idea. I use something similar but use sessions to remeber the sort order, is up to you.



Edited by michael
Back to Top
KCWebMonkey View Drop Down
Senior Member
Senior Member
Avatar
Go Chiefs!

Joined: 21 June 2002
Status: Offline
Points: 1319
Post Options Post Options   Thanks (0) Thanks(0)   Quote KCWebMonkey Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 6:45am
thanks michael, i thought it was something similar to that, but i couldn't figure it out.
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 8:41am
I'd change this:
If strSortOrder = "" THEN
strSortOrder = "asc"
END IF
to

If not strSortOrder = "desc" THEN
strSortOrder = "asc"
END IF

That way no one could change your sql statement by adding a sql statement to the querystring (sql injection)
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 17 July 2003 at 9:21am
true, better that way.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.