View Full Version : How to invert the order of "sort by"?

11-11-2003, 10:44 PM

I wonder how to make the links in the following code
invert my sorting order?


Pos / Name

1 John Doe
2 Jane Doe

If Pos and Name are the links and I click name I want
it to look like this:

2 Jane Doe
1 John Doe

and if I click it again it should look just like the first one again.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("db\2003.mdb")
set rs=Server.CreateObject("ADODB.recordset")

rs.open "select * from [" & Request.QueryString("competition") & "] order by [POINTS] desc, [POS] asc", conn
if rs.eof then
response.write "<hr><center>No records found</center><hr>"
end if

<table border="1" style="border-collapse: collapse" bordercolor="#000000" cellspacing="0" cellpadding="2">
<tr bgcolor="#000000">
<td width="50" align="center"><b><font color="#FFFFFF">Pos</font></b></td>
<td width="140" align="left"><b><font color="#FFFFFF">Namn</font></b></td>
<td width="50" align="center"><b><font color="#FFFFFF">Hcp</font></b></td>
<td width="50" align="center"><b><font color="#FFFFFF">V1</font></b></td>
<td width="50" align="center"><b><font color="#FFFFFF">V2</font></b></td>
<td width="50" align="center"><b><font color="#FFFFFF">Tot</font></b></td>
<td width="50" align="center"><b><font color="#FFFFFF">Thcp</font></b></td>
<td width="50" align="center"><b><font color="#FFFFFF">P</font></b></td>
dim background
<%do while not rs.eof %>
if background = "#ffffff" then
background = "#cccccc"
background = "#ffffff"
end if
<tr bgcolor="<%=background%>">
<td align="center"><%=rs.Fields("pos").Value%></td>
<td align="left"><%=rs.Fields("Fname").Value%>&nbsp;<%=rs.Fields("Lname").Value%></td>
<td align="center"><%=rs.Fields("hcp").Value%></td>
<td align="center"><%=rs.Fields("r1").Value%></td>
<td align="center"><%=rs.Fields("r2").Value%></td>
<td align="center"><%=rs.Fields("total").Value%></td>
<td align="center"><%=rs.Fields("Thcp").Value%></td>
<td align="center"><%=rs.Fields("Points").Value%></td>


set rs = nothing


11-11-2003, 11:34 PM
in your order by of your select statment you can use

ASC or DESC with the column name

make a variable that can be found from the form...etc...

"ORDER BY points DESC, pos ASC, name " + strSort