Sortering af kolonner ved udtræk fra DB
Med nedenstående kode vil jeg gerne kunne sortere mine kolonner ligesom i Windows stifinder (hvor man ved tryk på f.eks Dato kan sortere i ASC eller DESC.Imidlertid vil jeg gerne åbne siden med en default-sortering med ORDER BY, men ved ikke hvordan det kombineres med de øvrige sorteringsmuligheder.
Sidst vil det være fikst hvis man ved tryk på en knap genskaber default-sorteringen.
KODEN:
<html>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="dbconnect4.asp" -->
<%
soeg = Request.QueryString("soeg")
If soeg = "" Then
soegestreng = "'%'"
Else
soegestreng = "'%" & soeg & "%'"
End If
sort1= Request.QueryString("sort1")
If sort1 = "" Then
sort1 = "ASC"
ElseIf sort1 = "ASC" Then
sort1 = "DESC"
Else
sort1 = "ASC"
End If
sort2 = Request.QueryString("sort2")
If sort2 = "" Then
sort2 = "ASC"
ElseIf sort2 = "ASC" Then
sort2 = "DESC"
Else
sort2 = "ASC"
End If
sort3 = Request.QueryString("sort3")
If sort3 = "" Then
sort3 = "ASC"
ElseIf sort3 = "ASC" Then
sort3 = "DESC"
Else
sort3 = "ASC"
End If
sort4 = Request.QueryString("sort4")
If sort4 = "" Then
sort4 = "ASC"
ElseIf sort4 = "ASC" Then
sort4 = "DESC"
Else
sort4 = "ASC"
End If
sort5 = Request.QueryString("sort5")
If sort5 = "" Then
sort5 = "ASC"
ElseIf sort5 = "ASC" Then
sort5 = "DESC"
Else
sort5 = "ASC"
End If
sort6 = Request.QueryString("sort6")
If sort6 = "" Then
sort6 = "ASC"
ElseIf sort6 = "ASC" Then
sort6 = "DESC"
Else
sort6 = "ASC"
End If
sort7 = Request.QueryString("sort7")
If sort7 = "" Then
sort7 = "ASC"
ElseIf sort7 = "ASC" Then
sort7 = "DESC"
Else
sort7 = "ASC"
End If
sort8 = Request.QueryString("sort8")
If sort8 = "" Then
sort8 = "ASC"
ElseIf sort8 = "ASC" Then
sort8 = "DESC"
Else
sort8 = "ASC"
End If
sort9 = Request.QueryString("sort9")
If sort9 = "" Then
sort9 = "ASC"
ElseIf sort9 = "ASC" Then
sort9 = "DESC"
Else
sort9 = "ASC"
End If
sort10 = Request.QueryString("sort10")
If sort10 = "" Then
sort10 = "ASC"
ElseIf sort10 = "ASC" Then
sort10 = "DESC"
Else
sort10 = "ASC"
End If
sort11 = Request.QueryString("sort11")
If sort11 = "" Then
sort11 = "ASC"
ElseIf sort11 = "ASC" Then
sort11 = "DESC"
Else
sort11 = "ASC"
End If
%>
<%
Set list = Server.CreateObject ("ADODB.Recordset")
'list.Open "SELECT * FROM test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & " ORDER BY Ejer, TilgaaetAar, Lokalitet, LoebeNr, Sporvidde_mm, LokomotivNavn, Transmision, Status", Conn
'list.Open "SELECT * FROM test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & " ORDER BY Ejer, TilgaaetAar, Lokalitet, LoebeNr, Sporvidde_mm, LokomotivNavn, Transmision, Status, ID " & sort1 & ", Foto " & sort2 & "", Conn
'list.Open "SELECT * FROM test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & " ORDER BY ID " & sort1 & ", Foto " & sort2 & ", Ejer " & sort3 & ", TilgaaetAar, Lokalitet, LoebeNr, Sporvidde_mm, LokomotivNavn, Transmision, Status", Conn
'list.Open "SELECT * FROM test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & " ORDER BY ID " & sort1 & ", Foto " & sort2 & "", Conn
'list.Open "SELECT * FROM test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & " ORDER BY Foto " & sort2 & "", Conn
list.Open "SELECT * FROM test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & " ORDER BY ID " & sort1 & "", Conn
Set counter = Server.CreateObject ("ADODB.Recordset")
counter.Open "SELECT COUNT (*) AS antal from test WHERE test_Status =1 AND Anvendelse LIKE " & soegestreng & "", Conn
antal = counter.fields("antal")
Set dampcounter = Server.CreateObject ("ADODB.Recordset")
dampcounter.Open "SELECT COUNT (transmision) AS damptransmision from test WHERE test_Status =1 AND Transmision ='Damp' AND Anvendelse LIKE " & soegestreng & "", Conn
damptransmision = dampcounter.fields("damptransmision")
Set elcounter = Server.CreateObject ("ADODB.Recordset")
elcounter.Open "SELECT COUNT (transmision) AS eltransmision from test WHERE test_Status =1 AND Transmision IN ('Akkumulator-elektrisk', 'Kontakt-ledning') AND Anvendelse LIKE " & soegestreng & "", Conn
eltransmision = elcounter.fields("eltransmision")
Set motorcounter = Server.CreateObject ("ADODB.Recordset")
motorcounter.Open "SELECT COUNT (transmision) AS motortransmision from test WHERE test_Status =1 AND NOT Transmision ='Akkumulator-elektrisk' AND NOT Transmision ='Damp' AND NOT Transmision ='Kontakt-ledning' AND Anvendelse LIKE " & soegestreng & "", Conn
motortransmision = motorcounter.fields("motortransmision")
Set driftcounter = Server.CreateObject ("ADODB.Recordset")
driftcounter.Open "SELECT COUNT (status) AS driftstatus from test WHERE test_Status =1 AND Status ='I drift' AND Anvendelse LIKE " & soegestreng & "", Conn
status = driftcounter.fields("driftstatus")
%>
<html>
<head>
<title>testede industribanelokomotiver © SearchFunction Build V</title>
</head>
<body bgcolor="#FFFFFF">
</td></tr>
<tr><td bgcolor="#CCCCCC">
<form name="FrontPage_Form1" method="get" action="search_anvendelse06test.asp" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript">
<table style="border-left-color: #000000; border-top-color: #000000; border-collapse:collapse" bordercolorlight="#000000" bordercolordark="#000000" border="2" cellpadding="0">
<tr>
<th width="1300" valign="top" colspan="11 " bgcolor="#C0C0C0">
<p align="left">
<b>Søgeordet <font color="#008000"><% = soeg%></font> giver <font color="#008000"><% = antal%></font>
lokomotiver. Heraf <font color="#008000"><% = damptransmision%></font> damp-, <font color="#008000"><% = eltransmision%></font> el- og <font color="#008000"><% = motortransmision%></font> motor-drevne. <font color="#008000"><% = status%></font>
lokomotiver er i drift. </b></th>
</tr>
<td valign="top" align="center"><b><font size="2">
<%
sort1 = Request.QueryString("sort1")
if sort1 = "ASC" then
'ændre sort1 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort1=DESC&soeg=" & soeg & "'>ID Z</A>"
else
'ændre sort1 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort1=ASC&soeg=" & soeg & "'>ID A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort2 = Request.QueryString("sort2")
if sort2 = "ASC" then
'ændre sort2 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort2=DESC&soeg=" & soeg & "'>Foto Z</A>"
else
'ændre sort2 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort2=ASC&soeg=" & soeg & "'>Foto A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort3 = Request.QueryString("sort3")
if sort3 = "ASC" then
'ændre sort3 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort3=DESC&soeg=" & soeg & "'>Ejer Z</A>"
else
'ændre sort3 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort3=ASC&soeg=" & soeg & "'>Ejer A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort4 = Request.QueryString("sort4")
if sort4 = "ASC" then
'ændre sort4 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort4=DESC&soeg=" & soeg & "'>Tilg.<br>År Z</A>"
else
'ændre sort4 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort4=ASC&soeg=" & soeg & "'>Tilg.<br>År A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort5 = Request.QueryString("sort5")
if sort5 = "ASC" then
'ændre sort5 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort5=DESC&soeg=" & soeg & "'>Lokalitet Z</A>"
else
'ændre sort5 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort5=ASC&soeg=" & soeg & "'>Lokalitet A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort6 = Request.QueryString("sort6")
if sort6 = "ASC" then
'ændre sort6 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort6=DESC&soeg=" & soeg & "'>Lb.<br>Nr. Z</A>"
else
'ændre sort6 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort6=ASC&soeg=" & soeg & "'>Lb.<br>Nr. A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort7 = Request.QueryString("sort7")
if sort7 = "ASC" then
'ændre sort7 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort7=DESC&soeg=" & soeg & "'>Sporv.<br>mm Z</A>"
else
'ændre sort7 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort7=ASC&soeg=" & soeg & "'>Sporv.<br>mm A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort8 = Request.QueryString("sort8")
if sort8 = "ASC" then
'ændre sort8 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort8=DESC&soeg=" & soeg & "'>Lokomotiv<br>Fabrikat Z</A>"
else
'ændre sort8 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort8=ASC&soeg=" & soeg & "'>Lokomotiv<br>Fabrikat A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort9 = Request.QueryString("sort9")
if sort9 = "ASC" then
'ændre sort9 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort9=DESC&soeg=" & soeg & "'><b>Byg.<br>Nr. Z</A>"
else
'ændre sort9 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort9=ASC&soeg=" & soeg & "'><b>Byg.<br>Nr. A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort10 = Request.QueryString("sort10")
if sort10 = "ASC" then
'ændre sort10 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort10=DESC&soeg=" & soeg & "'><b>Trans-<br> mision Z</A>"
else
'ændre sort10 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort10=ASC&soeg=" & soeg & "'><b>Trans-<br> mision A</A>"
end if
%>
</font></b></td>
<td valign="top" align="center"><b><font size="2">
<%
sort11 = Request.QueryString("sort11")
if sort11 = "ASC" then
'ændre sort11 -> DESC link
response.write "<a href='search_anvendelse06test.asp?sort11=DESC&soeg=" & soeg & "'>Status Z</A>"
else
'ændre sort11 -> ASC link
response.write "<a href='search_anvendelse06test.asp?sort11=ASC&soeg=" & soeg & "'>Status A</A>"
end if
%>
</font></b></td>
</tr>
<%
While NOT list.EOF
%>
<td valign="top"><font size="2"><% Response.Write ("<a href='showroom02.asp?soeg=" & list.Fields("ID") & "'target=>" & list.Fields("ID") & "</a>")%> </font></td>
<td valign="top"><font size="2"><p align="center"><% = list.Fields("Foto")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("Ejer")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("TilgaaetAar")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("Lokalitet")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("LbNr")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("Sporvidde_mm")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("LokomotivNavn")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("ByggeNr")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("Transmision")%> </font></td>
<td valign="top"><font size="2"><% = list.Fields("Status")%> </font></td>
</tr>
<%
list.MoveNext
Wend
%>
<tr>
<th width="1300" valign="top" colspan="11" bgcolor="#C0C0C0">
<p align="right">
<font size="1" face="Arial"><span style="font-weight: 400">©
SearchFunction Build V</span></font> </th>
</tr>
</table>
</form>
</font>
<p align="center"><b><font face="MS Sans Serif" size="1">
</b>
</b>
</body>
</html>
<%
list.close
set list = nothing
%>