Hi All,
Im a bit of a noob and i'm hoping that what i'm trying to do is fairly common and Im totally stuck and really need some help...
I have an access database that i need to return some results from. At present I have an ASP Sript that Will return all the records in decending order by ID number... This is Perfect.
However i only Wish for it to Return the three most Recent Results.
Here is the code im Using to return ALL the results:
<%
' Declaring variables
Dim rs, data_source, no
no = 0
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("form.mdb")
' Creating Recordset Object and opening the database
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM users ORDER BY id DESC ", data_source
' Looping through the records to show all of them
While Not rs.EOF
Response.Write "<form action='del.asp' method='post'>"
Response.Write "Name : " & rs("name") & "<br>"
Response.Write "Email : " & rs("email") & "<br>"
Response.Write "Country : " & rs("country") & "<br>"
Response.Write "Comments : " & rs("comments") & "<br>"
Response.Write "<input type='hidden' name='id' value='" & rs("id") & "'>"
Response.Write "<input type='submit' value='Delete'>" & "<br>"
Response.Write "</form>"
no = no + 1
rs.MoveNext
Wend
' Done. Now close the Recordset
rs.Close
Set rs = Nothing
Response.Write "<p>Total Records Found : " & no
%>
- <%
- ' Declaring variables
- Dim rs, data_source, no
- no = 0
- data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
- Server.MapPath("form.mdb")
-
- ' Creating Recordset Object and opening the database
- Set rs = Server.CreateObject("ADODB.Recordset")
- rs.Open "SELECT * FROM users ORDER BY id DESC ", data_source
-
-
- ' Looping through the records to show all of them
- While Not rs.EOF
- Response.Write "<form action='del.asp' method='post'>"
- Response.Write "Name : " & rs("name") & "<br>"
- Response.Write "Email : " & rs("email") & "<br>"
- Response.Write "Country : " & rs("country") & "<br>"
- Response.Write "Comments : " & rs("comments") & "<br>"
- Response.Write "<input type='hidden' name='id' value='" & rs("id") & "'>"
- Response.Write "<input type='submit' value='Delete'>" & "<br>"
- Response.Write "</form>"
- no = no + 1
- rs.MoveNext
- Wend
-
- ' Done. Now close the Recordset
- rs.Close
- Set rs = Nothing
-
- Response.Write "<p>Total Records Found : " & no
- %>
-
As mentioned above - this script displays ALL the results in the Table. I only want the Newest 3 results to be returned.
I don't know what it is i need to change to only get the three most recent items from the access database. I've tried putting
"SELECT * FROM `users` LIMIT 0, 3 "
in various places in the script in addition to what I have above. Please can anyone advise what i need to change or where on earth i am to put the LIMIT Variable or anything.
Thanks to Any Help In Advance
Jy