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 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    display records in order

    i have the following code to dislay the records of a database, but it shows them in order of id number, when i would like them to be shown in order of date then time
    e.g. if i had the following records
    27/04/02 09:45 event1
    27/04/02 07:45 event4
    30/04/02 09:45 event2
    28/04/02 019:45 event8
    it would display them as:
    27/04/02 07:45 event1
    27/04/02 09:45 event4
    28/04/02 19:45 event2
    30/04/02 09:45 event8
    my current code is:
    Code:
    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor="white" text="black">
    <%
    'Dimension variables
    Dim adoCon 			'Holds the Database Connection Object
    Dim rsGuestbook			'Holds the recordset for the records in the database
    Dim strSQL			'Holds the SQL query for the database
    
    
    
    'Create an ADO connection odject
    Set adoCon = Server.CreateObject("ADODB.Connection")
    
    'Set an active connection to the Connection object using a DSN-less connection
    adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
    
    'Set an active connection to the Connection object using DSN connection
    'adoCon.Open "DSN=guestbook"
    
    'Create an ADO recordset object
    Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
    
    'Initialise the strSQL variable with an SQL statement to query the database
    strSQL = "SELECT tblComments.date, tblComments.time, tblComments.event FROM tblComments;"
    
    'Open the recordset with the SQL query 
    rsGuestbook.Open strSQL, adoCon
    
    'Loop through the recordset
    Do While not rsGuestbook.EOF
    	
    	'Write the HTML to display the current record in the recordset
    	Response.Write ("<br>")
    	Response.Write (rsGuestbook("date"))
    	Response.Write ("<br>")
    	Response.Write (rsGuestbook("time"))
    	Response.Write ("<br>")
    	Response.Write (rsGuestbook("event"))
    	Response.Write ("<br>")
    
    	'Move to the next record in the recordset
    	rsGuestbook.MoveNext
    
    Loop
    
    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing
    %>
    </body>
    </html>
    thanks in advance
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    strSQL = "SELECT tblComments.date, tblComments.time, tblComments.event FROM tblComments ORDER BY tblComments.date, tblComments.time"
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks i`ll try that.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    P.S. If you want the latest time first, try:

    strSQL = "SELECT tblComments.date, tblComments.time, tblComments.event FROM tblComments ORDER BY tblComments.date, tblComments.time DESC"

    DESC stands for "descending" as opposed to the default, which is "ascending" (ASC).
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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