...

View Full Version : problme with sorting



Bluemonkey
02-27-2003, 10:35 AM
i am trying to sort a colum in my table by asc or desc i am trying to do it like this at the monet


<script language="VBScript">
dim mbOrder, s

sub headerclick(sort)

mborder = not mborder

if mborder then
window.location.href = "viewjobs.asp?sortby=" & sort & "&SortOrder=1"
else
window.location.href = "viewjobs.asp?sortby=" & sort & "&SortOrder=0"
end if

s = window.location.href

msgbox(s)

end sub

</script>

<a href="#" onclick="headerclick('jobtitle')">Job Title<img src="../images/up.gif" border="0"></a>

so when the user clicks on the title is sorts it by ASC then if you click it again by DESC.

please can some one help me, or if there is an easyer way do tell

thank you very much for the help

Roy Sinclair
02-27-2003, 09:55 PM
I'm not sure what your problem here is. Could you give more detail on what the problem is?

whammy
02-28-2003, 01:09 AM
I know what BlueMonkey is trying to do... I will provide some code tomorrow if I can remember, I have a perfectly working application that does exactly this. :)

Wish you didn't have to wait but I have this code at work...

Bluemonkey
02-28-2003, 09:19 AM
i need it to sort by ASC when the user clicks on the title of the colume and then when the page has reloaded and the user clicks on the same title it sorts by DESC

whammy
02-28-2003, 10:53 PM
Here are the important parts of the code I'm using to do this:


OrderBy = Request.QueryString("OrderBy")

If OrderBy = "" Then OrderBy = "ID DESC"

If InStr(1,OrderBy,"DESC") = False Then
SortImage = "images/downarrow.gif"
ReverseSwitchOrder = " DESC"
SwitchOrder = ""
Else
SortImage = "images/uparrow.gif"
ReverseSwitchOrder = ""
SwitchOrder = " DESC"
End If


For Each fld In rs.Fields
Response.Write(Indent(10) & "<td class=""productheader"" align=""center""><a class=""orderby"" href=""showreport.asp?Q=" & WhichReport & "&OrderBy=" & fld.Name)
If InStr(1,OrderBy,fld.Name) > 0 Then
Response.Write(ReverseSwitchOrder)
Else
Response.Write(SwitchOrder)
End If
Response.Write(""">" & Replace(fld.Name,"_"," ") & "</a><br />")
If InStr(1,OrderBy,fld.Name) > 0 Then
Response.Write("<img src=""" & SortImage & """ width=""10"" height=""10"" alt="""" />")
Else
Response.Write("<img src=""images/space.gif"" width=""10"" height=""10"" alt="""" />")
End If
Response.Write("</td>" & vbCrLf)
fldcount = fldcount + 1
Next

Make any sense? :D

whammy
02-28-2003, 10:54 PM
Oops, then of course I use this:

MyQuery = "SELECT * FROM TableName ORDER BY " & OrderBy

Bluemonkey
03-05-2003, 02:18 PM
thanks for the help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum