SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Grr..more help?

  1. #1
    SitePoint Enthusiast MrK2's Avatar
    Join Date
    Jul 2001
    Location
    British Columbia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grr..more help?

    Oh what would I ever do without this forum?

    Having a problem with rs.Sort. I'd like to sort the results of a table based on a QueryString value. For example, click on a link on the results page to view the page again, but with a different sort.

    Here's what I tried:

    Code:
    If Request.Querystring("Sort") Then
    	Dim rqsNewSort
    	rqsNewSort = Request.Querystring("Sort")
    	rs.Sort = "" & rqsNewSort & "desc"
    Else
    	rs.Sort = "MatchDate desc"
    End If
    "MatchDate desc" would be the default sort. I guess I need to know how to properly use a variable in the rs.Sort function.

    Or, if someone knows a better way to accomplish what I need here, I'm open to any suggestions.

  2. #2
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use ORDER BY in your SQL statement.

    > SELECT * FROM tblDemo WHERE demGroup='beta' ORDER BY demTitle"
    > SELECT * FROM tblDemo WHERE demGroup='beta' ORDER BY demTitle DESC"

    etc, etc
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  3. #3
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,294
    Mentioned
    123 Post(s)
    Tagged
    1 Thread(s)
    KodeKrash is correct. It would just be easiest to sort it in the SQL statement itself.

    So you would have

    Code:
    <%
    dim sortvalue, strSQl
    SortValue = request.form("Sort")
    
    strSQL = "SELECT field1, field2 from TABLENAME"
    if SortValue <> "" then
       strSQL = strSQL & " ORDER BY " & SortValue & " DESC"
    else
       strSQL = strSQL & " ORDER BY MatchDate DESC"
    end if
    rs.open strSQL, my_conn
    %>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  4. #4
    SitePoint Enthusiast MrK2's Avatar
    Join Date
    Jul 2001
    Location
    British Columbia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ugh, I'm not really sure how to implement that. I'm using a Recordset to display the data, and have already connected to it in the preceding code.

    Code:
    Const adCmdTableDirect = &H0200
    Const adLockReadOnly = 1
    Const adOpenStatic = 1
    Const adUseClient = 3
    
    Dim connStr
    connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
    Server.MapPath("./matches.mdb")
    
    Dim rs
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorLocation = adUseClient
    rs.Open "Matches", connStr, adOpenStatic, adLockReadOnly, adCmdTableDirect
    Next comes the code I pasted above.

    I later use two subroutines to display each row of table data in alternating colors, like so (this section comes after a line of HTML to create headings for the table):

    Code:
    While Not rs.EOF
    	' *** Alternate row colors
    	ShowMatchBlack rs("MatchDate"), rs("Opponent"), rs("Score1"), rs("Score2"), rs("Score3"), rs("Winner")
    	rs.MoveNext
    	If Not rs.EOF Then
    		ShowMatchBlue rs("MatchDate"), rs("Opponent"), rs("Score1"), rs("Score2"), rs("Score3"), rs("Winner")
    		rs.MoveNext
    	End If
    Wend
    Response.Write "</table>"
    I have no idea where I should put the SQL statement. Is it possible just to put it right in the code from my first post, after having already connected to the Recordset? Or should I use one big If statement to involve two totally different connections based on the presence of Request.Querystring("Sort")?

    Please forgive me if I'm missing something obvious here, I'm still pretty new.


Bookmarks

Posting Permissions

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