denny911 Posted November 22, 2005 Share Posted November 22, 2005 I have this piece of code.<%Set conn = Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("mydb.mdb"))Set rs = Server.CreateObject("ADODB.recordset")dataSQL = " SELECT * FROM shouts ORDER BY time"rs.Open dataSQL, connp=rs.GetRows(10,0)%>In this code, I'm able to get 10 records (those that were added first), since their time is oldest.What I need is to get 10 last added records from the table "shouts", that is, records should be sorted from the newest time to the latest.What code should I use to accomplish that?Thanks! Link to comment Share on other sites More sharing options...
Skemcin Posted November 22, 2005 Share Posted November 22, 2005 SELECT TOP 10 *FROM shoutsORDER BY time DESCIf you are using an auto-number as your primary key, you could always do this too:SELECT TOP 10 *FROM shoutsORDER BY ID DESC Link to comment Share on other sites More sharing options...
denny911 Posted November 22, 2005 Author Share Posted November 22, 2005 SELECT TOP 10 *FROM shoutsORDER BY time DESCIf you are using an auto-number as your primary key, you could always do this too:SELECT TOP 10 *FROM shoutsORDER BY ID DESC<{POST_SNAPBACK}> Ok, but how i display individual records? with my code i put this:<% Response.Write(p(0,0)) %> for the first record and the first field in the first record, and so on..what i put using your code in order to display records or fields where i want them to appear? Link to comment Share on other sites More sharing options...
Skemcin Posted November 22, 2005 Share Posted November 22, 2005 sorry, thats where I have to back out - I'm not the resident ASP expert. I'm sure someone will be able to help. I just figured you were caught up on the SQL statement - sorry I can't help with the ASP. Link to comment Share on other sites More sharing options...
degsy Posted November 22, 2005 Share Posted November 22, 2005 Usually you would go with the SQL that Skemcin has posted and use a loop to iterate through the recordse.g. if you has two fields called user_id and username in a table called USER Set rs = Server.CreateObject("ADODB.recordset")dataSQL = "SELECT TOP 10 user_id, username FROM [USER] ORDER BY user_id DESC"rs.Open dataSQL, conn <table border="1" cellpadding="0" cellspacing="2"> <tr> <td>user_id</td> <td>username</td> </tr> <% While NOT rs.EOF%> <tr> <td><%=rs("user_id")%></td> <td><%=rs("username")%></td> </tr> <% rs.MoveNext()Wend%></table> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now