View | Statement If there are many records on the page, in many cases, it is more efficient to sort the information alphabetically in descending order than the traditional ascending sort display. With your familiar ORDER BY clause, you can easily add this feature to the page, allowing users to control the views that their records display.
Suppose you have a page whose name is customers.asp, page execution selects all records from the Customers table and sorts the customer's last name in alphabetical order. Previously we have seen the sorted code, in order to achieve reverse ordering, you only need to add desc after an order BY expression:
SQL = "Select C_lastname, C_firstname, c_email from Customers order by C_lastnamedesc"
It's not bad to be in static mode. However, you may want to modify the above code to provide new GUI functionality:
<a href= "customers.asp" >sort ascending</a> | <a href= "Customers.asp?sort=desc" >sort descending</a>
<P>
<%
SQL = "Select C_lastname, C_firstname, c_email from Customers order by C_lastname" & Sort & ""
Set Objrec = objConn.Execute (SQL)
While not objrec.eof
Response.writeobjrec ("C_lastname") & "," & Objrec ("C_firstname") & "
"& Objrec (" C_email ") &" <P> "
Objrec.movenext
Wend
%>
The first link in the above code allows the user to modify the view of the page. You can overload the same page to view this information, but in the case of the Sort Descending link, the page assigns a value to the sort variable. Then, within the SQL statement, you do not specify DESC but instead take the value of the sort variable.
The next thing to do is to read the value of the sort at the top of the page.
<%
Sort = Request.QueryString ("sort")
%>
The code above checks out the available values for sort from the URL.
Doesn't make you too much effort, you can also adjust the same page allows users to sort specific columns. A simple Select Menu form control listing the sort by option can be a more convenient measure.