Forums
This topic is locked
dynamic sorting
24 Jul 2007 22:27:44 john g posted:
hey all,i'm pretty new at asp and databases, so i'm having trouble with advanced sorting. I'm using dreamweaver csIII, VBScript, and an access db. i have a left navigation column with 10 links that when clicked bring in information from the database. i then have five category's that i want users to be able to sort by once the information is displayed. i know this may be rather routine, so any help or direction to tutorials would be much appreciated. thanks.
Replies
Replied 01 Aug 2007 20:05:47
01 Aug 2007 20:05:47 dave blohm replied:
this is how I would to it...
<pre id=code><font face=courier size=2 id=code>
<%
' ::::: THIS EXAMPLE ASSUMES SEVERAL THINGS...
' ::::: 1. YOU ARE PASSING FORM DATA TO THIS PAGE USING A
' ::::: VARIABLE NAMED 'SORT_ORDER'.
' :::::
' ::::: 2. THAT THE POSSIBLE VALUES THAT MAY BE SUBMITTED
' ::::: ARE '1', '2', '3', AND '4'.
' :::::
' ::::: 3. THAT YOU WANT THE DEFAULT SORT ORDER IF A VARIABLE
' ::::: IS *NOT* PASSED OR AN UNSPECIFIED VARIABLE IS PASSED
' ::::: TO BE BY LAST NAME IN ASCENDING ORDER (THE CASE ELSE
' ::::: STATEMENT).
select case request.form("sort_order"
' ::::: COMMENT OUT THE LINE ABOVE AND UNCOMMENT THE LINE BELOW
' ::::: IF YOU ARE USING THE GET METHOD INSTEAD OF POST
' select case request.querystring("sort_order"
case "1"
var_sort = "ORDER BY id ASC"
case "2"
var_sort = "ORDER BY id DESC"
case "3"
var_sort = "ORDER BY name_first ASC"
case "4"
var_sort = "ORDER BY name_first DESC"
case else
var_sort = "ORDER BY name_last ASC"
end select
Set rs_tutorial_cmd = Server.CreateObject ("ADODB.Command"
rs_tutorial_cmd.ActiveConnection = cs_my_connection_string
rs_tutorial_cmd.CommandText = "SELECT * FROM my_table " & var_sort
Set rs_tutorial = rs_tutorial_cmd.Execute
var_sort = ""
%>
Hope this helps...
</font id=code></pre id=code>
- Doc
Progress is made by the discontent.
Edited by - daveblohm on 02 Aug 2007 18:07:07
<pre id=code><font face=courier size=2 id=code>
<%
' ::::: THIS EXAMPLE ASSUMES SEVERAL THINGS...
' ::::: 1. YOU ARE PASSING FORM DATA TO THIS PAGE USING A
' ::::: VARIABLE NAMED 'SORT_ORDER'.
' :::::
' ::::: 2. THAT THE POSSIBLE VALUES THAT MAY BE SUBMITTED
' ::::: ARE '1', '2', '3', AND '4'.
' :::::
' ::::: 3. THAT YOU WANT THE DEFAULT SORT ORDER IF A VARIABLE
' ::::: IS *NOT* PASSED OR AN UNSPECIFIED VARIABLE IS PASSED
' ::::: TO BE BY LAST NAME IN ASCENDING ORDER (THE CASE ELSE
' ::::: STATEMENT).
select case request.form("sort_order"
' ::::: COMMENT OUT THE LINE ABOVE AND UNCOMMENT THE LINE BELOW
' ::::: IF YOU ARE USING THE GET METHOD INSTEAD OF POST
' select case request.querystring("sort_order"
case "1"
var_sort = "ORDER BY id ASC"
case "2"
var_sort = "ORDER BY id DESC"
case "3"
var_sort = "ORDER BY name_first ASC"
case "4"
var_sort = "ORDER BY name_first DESC"
case else
var_sort = "ORDER BY name_last ASC"
end select
Set rs_tutorial_cmd = Server.CreateObject ("ADODB.Command"
rs_tutorial_cmd.ActiveConnection = cs_my_connection_string
rs_tutorial_cmd.CommandText = "SELECT * FROM my_table " & var_sort
Set rs_tutorial = rs_tutorial_cmd.Execute
var_sort = ""
%>
Hope this helps...
</font id=code></pre id=code>
- Doc
Progress is made by the discontent.
Edited by - daveblohm on 02 Aug 2007 18:07:07
Replied 02 Aug 2007 17:17:43
02 Aug 2007 17:17:43 john g replied:
thanks dave blohm
Replied 02 Aug 2007 18:06:17
02 Aug 2007 18:06:17 dave blohm replied:
opps...made a mistake...left out ORDER BY within the select statement...see above.
- Doc
Progress is made by the discontent.
- Doc
Progress is made by the discontent.