Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 sorting records in db
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

skylar
Starting Member

23 Posts

Posted - 19 April 2001 :  00:20:32  Show Profile
Hi, I'm new to databasing with ASP. I have a access database with one column thats a date. How do I sort the records from newest to oldest before displaying them? Thanks...

Doug G
Support Moderator

USA
6493 Posts

Posted - 19 April 2001 :  01:09:22  Show Profile
Create your recordset with a statement like 'SELECT date FROM table ORDER BY date DESC'

======
Doug G
======
Go to Top of Page

skylar
Starting Member

23 Posts

Posted - 19 April 2001 :  01:41:38  Show Profile
Really, how do you do that?

Go to Top of Page

mafifi
Junior Member

USA
308 Posts

Posted - 17 May 2001 :  18:58:30  Show Profile  Send mafifi an ICQ Message
The following code will return names and states from an access DB called Samples.mdb. Yoy can download the Access file from http://www.media-2000.com/samples.mdb
Make sure to set the "DSN=whatevername" to whatever you want. And you should be all set. Did I mention that the code is courtesy of Kathi at http://www.web-savant.com/users/kathi/default.htm

<html>
<head>
<title>ASP Sample Script</title>
</head>
<body bgcolor="#ffffff">
<center>
<table width=600 border=1 cellpadding=5 cellspacing=0>
<%
' first create a recordset object
set rs=Server.CreateObject("adodb.Recordset")
' next set up a connection string
connectme="DSN=whatevername"
' now set up a query for the database
sqlstmt = "SELECT * from Sample ORDER BY State DESC"
' connect to the database and execute query
rs.open sqlstmt, connectme
' if the recordset is empty we will quit
' and display a message using a conditional
' if...then...else statement
If rs.eof then
response.write "<center>"
response.write "There are no records"
response.write "<br>Please check back later"
response.write "</center>"
Else
response.write "<tr>"
response.write "<td colspan=4 align=""center"">"
response.write "<i><h1>Sample Script 1</a>"
response.write "</tr>"
' let's save some typing by setting start & end html
' for each cell to a variable
StartCell="<td><font size=2>"
EndCell="</font></td>"
With Response
.write "<tr>"
.write StartCell & "Name" & EndCell
.write StartCell & "City" & EndCell
.write StartCell & "State" & EndCell
.write StartCell & "Country" & EndCell
.write "</tr>"
End With
' loop through the records and display the information
' using a Do While...Loop statement
Do while not rs.eof
Name = rs("Name")
City = rs("City")
State = rs("State")
Country = rs("Country")
With Response
.write "<tr>"
.write StartCell & City & EndCell
.write StartCell & State & EndCell
.write StartCell & Country & EndCell
.write "</tr>"
End With
rs.MoveNext ' moves to next record
loop ' go get another record
End If
%>
</td>
</tr>
</table>

</center>
</body>
</html>




Mo
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.23 seconds. Powered By: Snitz Forums 2000 Version 3.4.07