...

View Full Version : display records in order



scroots
07-28-2002, 09:05 PM
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:


<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

glenngv
07-29-2002, 03:32 AM
strSQL = "SELECT tblComments.date, tblComments.time, tblComments.event FROM tblComments ORDER BY tblComments.date, tblComments.time"

scroots
07-29-2002, 07:10 PM
thanks i`ll try that.

scroots

whammy
07-31-2002, 01:16 AM
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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum