Show x Number of records from the database

Show me a few of the most recent records added to the database, and individually link them to their full record. What we have this thing do, is just show the last few (newest first) records/articles added to the database along with the date that they were added. You could just as easily link this to your inventory, or any other table in your database, but we are using it for news here, so here is the code to do that.

For demonstration purposes only! Please be aware of SQL Injection, and techniques to avoid.
<%
 Const adUseClient = 3
 Const adOpenStatic = 3
 ' first, make a conn to your db named cnDZ!
 ' then call it and use it here:
 Set rs = Server.CreateObject("ADODB.RecordSet")
 rs.CursorLocation = adUseClient
 rs.CacheSize = 5
 rs.Open "SELECT * FROM TBLNEWS ORDER BY THEDATE DESC", cnDZ, adOpenStatic
 If Not rs.EOF Then
     rs.MoveFirst
     rs.PageSize = 2 'how many news items should we show?
     maxcount = cint(rs.PageCount)
     howmanyrecs = 0
 While Not rs.EOF And howmanyrecs < rs.pagesize
     Response.Write"<a href=""myPage.asp?specific="&rs("NEWSID")&""" target=""_top"">"&_
           ""&Left(rs("THEDATE"),10)&"</a><br>"&Left(rs("NEWS"),99)&"...<br><br>"
     rs.MoveNext
     howmanyrecs = howmanyrecs + 1
 Wend
 Else
 Response.Write"No News Found!"
 End If
 rs.Close
 Set rs = Nothing
 %>


top 4 recordsets limit number of recs returned


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site