classic asp rs loop from sql database on selected rows possible?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar999
    New Member
    • Mar 2010
    • 120

    classic asp rs loop from sql database on selected rows possible?

    hi guys

    i can perform an asp rs loop from a sql db fine - my question is how do I only loop through a selection of records? for example 1-5? or 6-10?

    below is my code;
    Code:
    If objRS35and36.Eof Then 
    Response.write "<div align='center'>Sorry there are no current records.</div>" 
    Else 
    
    Response.Write "<table align=""center"" id=""flightspecialscontainer"" cellpadding=""0"" cellspacing=""0"">"
    Response.Write "<tr><td>"
    
    Do while not objRS35and36.Eof 
    Response.Write "<table align=""center"" cellpadding=""0"" cellspacing=""0"" id=""flightspecialroutetable"">"
    Response.Write "<tr><td>" & objRS35and36("Anchor_Tag") & vbCrLf & "<fieldset class=""fieldsetspecialpricebox"">" & vbCrLf
    Response.Write "<legend>" & vbCrLf & "<span class=""specialtitlesmall"">" & objRS35and36("Flight_Route") & "</span>" & vbCrLf & "</legend>" & vbCrLf
    Response.Write "<table align=center cellpadding=0 cellspacing=0 class=""specialpricetable"">" 
    
    Response.Write "<tr>" & vbCrLf & "<td class=""pricetd"">&pound;" & objRS35and36("Price_Band_1") & "</td>" & vbCrLf
    Response.Write "<td class=""datetd""><span class=""monthspan"">" & objRS35and36("Month_Band_1") & "&nbsp;</span>" & objRS35and36("Date_Band_1") & "</td>" & vbCrLf & "</tr>" & vbCrLf
    Response.Write "<tr>" & vbCrLf & "<td class=""pricetd"">&pound;" & objRS35and36("Price_Band_2") & "</td>" & vbCrLf
    Response.Write "<td class=""datetd""><span class=""monthspan"">" & objRS35and36("Month_Band_2") & "&nbsp;</span>" & objRS35and36("Date_Band_2") & "</td>" & vbCrLf & "</tr>" & vbCrLf
    'end table setup
    Response.Write "<td colspan=""2"" class=""specialbookbuttontd""><a class=""button"" href=""#BackToTop"" onClick=""change_booking(" & objRS35and36("Book_Button") & ")"">BOOK NOW !</a></td>"
    Response.Write "</tr>" & vbCrLf & "</table>" & vbCrLf & "</fieldset>"  & vbCrLf
    Response.Write "</td></tr></table>" & vbCrLf & vbCrLf
    
    'move to the next record in the recordset
    objRS35and36.movenext
    
    Loop 
    end if
    thanks in advance
    omar
  • omar999
    New Member
    • Mar 2010
    • 120

    #2
    oh my God what a newbie question im posting first thing in the morning. I've had a little think about this and I've worked it out.

    All I've done is modified my sql statement to select certain rows by their ID - so something like select * from column name where ID in (1, 2, 3) etc etc

    then the loop only loops through these 3 rows! problem solved. :)

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      I was going to suggest changing your "do until rs.eof" to "for x = 0 to 4"
      Code:
      for x = 0 to 4
         '...
         rs.movenext
         if rs.eof then exit for
      next
      but I'm glad you found a solution.

      Jared

      Comment

      Working...