add a loop, next

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    add a loop, next

    Hi, I know this is simple thing but always beats me.

    I have this script that works fine, I just want to add a loop so that it returns all the entries instead of just one.

    Code:
    <% 
    ' ADO Constant. Dont change this 
    ' Connection string and SQL statement 
    Dim sql , connStr 
    sql  = "Select description  FROM tblGreetingPostCards"
    connStr = " Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/database.mdb" ) 
    ' Opening database 
    Dim rs 
    Set rs = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, connStr, 3, , adCmdText 
    ' Generating random number from total number of records 
    Dim intRnd 
    Randomize Timer 
    intRnd = (Int(RND * rs.RecordCount)) 
    ' Now moving the cursor to random record number 
    rs.Movenext 
    ' Showing the random statement 
    Response.Write " <b><a class=""men"" href=""art.asp?art=" & rs("description") & """>" & rs("description") & " </a></b><br><br>"
     
    ' Closing the database 
    rs.Close 
    Set rs = Nothing 
    %>
    Any pointer would be great, I have tried adding loo and next just not sure of the right way.
    Thanks
    Richard
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Richard,

    To loop through every record in the recordset use:
    Code:
    Do Until rs.EOF
         'Do something with the record
         rs.MoveNext
    rs.Loop
    Is this what you mean?

    Dr B

    Comment

    • fran7
      New Member
      • Jul 2006
      • 229

      #3
      Thanks Dr B, worked a treat
      Richard

      Comment

      Working...