Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to invert the order of "sort by"?

    Hi,

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

    example:

    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.

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <%
    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
    %>
    
    <center>
    <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>
    </tr>
    <%
    dim background
        background="#cccccc"
    %> 
    <%do while not rs.eof %>
    <%
    if background = "#ffffff" then
       background = "#cccccc"
    else
       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>
    </tr>
    <%rs.movenext
    Loop%>
    </table>
    
    </center>
    
    </body>
    </html>
    <%
    set rs = nothing
    %>
    Thanks
    /Speedy

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •