Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying # records

    Instead of looping through my access database, I was would like to display the most recent five records posted in the database. how would I go about doing this?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In sql server I know you can do

    Select TOP 5 * FROM tbFOO ordery by datefield

    I would guess this works in Access too.

    edit:
    put in an order by predicate for the date
    does this sig match?

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont think the server I'm working on has SQL server

  • #4
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok I got that to work, though being a novice I dont know how well its coded.

    What I need ultimatly is to ave it display the 5 newest records. My database table has three fields (id, title, post). Im not really sure how to set up the date. Here is my code, maybe someone can show me what to replace or what to add?

    Code:
    <%
    ' Declaring variables
    Dim rs, data_source
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open Server.MapPath("admin/data/data.mdb")
    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open "Select TOP 5 * from news", conn
    
    
    ' Looping through the records to show all of them
    While Not rs.EOF
    Response.Write "<table width=""700"" border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td valign=""top""><table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td class=""cat-2""> <table border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td><table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"" class=""cat-border""><tr><td class=""cat-title"" width=""37""><img src=""images/cat_symbol.gif"" alt="""" width=""38"" height=""22"" /></td><td class=""frame-title"">"
    Response.Write rs("title")
    Response.Write "</td></tr></table></td></tr></table></td></tr><tr><td><table width=""90%"" border=""0"" align=""center"" cellpadding=""3"" cellspacing=""0""><tr><td class=""boxtext"" valign=""top"">"
    Response.Write(Replace(rs("post"), vbCrLf, "<br />"))
    Response.Write "</td></tr></table></td></tr></table><br /></td></tr></table>"
    rs.MoveNext
    Wend
    ' Done. Now close the Recordset
    rs.Close
    Set rs = Nothing
    	%>

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind I think I have it. Still feel free to let me know if it is coded poorly. I dont wanna take down the server!

    Code:
    <%
    ' Declaring variables
    Dim rs, data_source
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open Server.MapPath("admin/data/data.mdb")
    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open "Select TOP 5 * from news ORDER BY id DESC", conn
    
    
    ' Looping through the records to show all of them
    While Not rs.EOF
    Response.Write "<table width=""700"" border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td valign=""top""><table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td class=""cat-2""> <table border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td><table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"" class=""cat-border""><tr><td class=""cat-title"" width=""37""><img src=""images/cat_symbol.gif"" alt="""" width=""38"" height=""22"" /></td><td class=""frame-title"">"
    Response.Write rs("title")
    Response.Write "</td></tr></table></td></tr></table></td></tr><tr><td><table width=""90%"" border=""0"" align=""center"" cellpadding=""3"" cellspacing=""0""><tr><td class=""boxtext"" valign=""top"">"
    Response.Write(Replace(rs("post"), vbCrLf, "<br />"))
    Response.Write "</td></tr></table></td></tr></table><br /></td></tr></table>"
    rs.MoveNext
    Wend
    ' Done. Now close the Recordset
    rs.Close
    Set rs = Nothing
    	%>

  • #6
    Regular Coder
    Join Date
    Jul 2004
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts
    looks ok!

    i wouldent show the path to your database tho if i were you.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Or put the db in a directory that's not downloadable, usually just above the web root. Then, you would access it this way:

    Server.MapPath("../admin/data/data.mdb")


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •