Thread: Repeat loop?

    #1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    69
    Rep Power
    5

    Repeat loop?


    Hi guys

    I hope this is possible. Let's say I have the following code on my page:

    Code:
    <%
      sqlStr = "SELECT top 6 imageurl from mytable where orderid = '123456' GROUP BY carimage"
    
      oRs.Open sqlStr, oDBConn 
      If oRs.eof then
    %>
    No images
    <%
      Else
    
      Do while not oRs.eof
      %>
    
    <img src="<%=oRs("imageurl")%>"><br>
    
    <%
      oRs.MoveNext
      loop 
    
      End If
    %>
    If I have 6 records in my table which have an orderid value of "123456" then 6 images will appear on my page like so

    <img src="http://www.mywebsite.co.uk/image1.jpg">
    <img src="http://www.mywebsite.co.uk/image2.jpg">
    <img src="http://www.mywebsite.co.uk/image3.jpg">
    <img src="http://www.mywebsite.co.uk/image4.jpg">
    <img src="http://www.mywebsite.co.uk/image5.jpg">
    <img src="http://www.mywebsite.co.uk/image6.jpg">

    ...which is fine. However, if I only have 4 records then only 4 images will appear on my page. What I would love is that IF there is less then 6 images then the results loop round again making up the 6. So, for example, if there are only 4 records then the first 2 images of that 4 will appear again which makes up the 6. So in this example my page would look like this:

    <img src="http://www.mywebsite.co.uk/image1.jpg">
    <img src="http://www.mywebsite.co.uk/image2.jpg">
    <img src="http://www.mywebsite.co.uk/image3.jpg">
    <img src="http://www.mywebsite.co.uk/image4.jpg">
    <img src="http://www.mywebsite.co.uk/image1.jpg">
    <img src="http://www.mywebsite.co.uk/image2.jpg">

    I'm hoping my explanation makes sense? If so, how would I do this? Any help would be fully appreciated

    Best regards

    Rod from the UK
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2014
    Posts
    69
    Rep Power
    5
    Hi guys

    Apologies. I've just realised that this is in the wrong forum and is probably why I'm not getting a response. Therefore I will end this thread and create a new one in the database forum where it is better suited.

    Best regards

    Rod from the UK

Similar Threads

  1. Can I exclude repeat entries in a repeat region?
    By malhyp in forum ASP Development
    Replies: 8
    Last Post: February 27th, 2007, 05:44 AM
  2. Repeat region IF index = multiple of 5 (LOOP?)
    By farmboy in forum ASP Development
    Replies: 5
    Last Post: January 8th, 2007, 05:37 AM
  3. Replies: 5
    Last Post: August 11th, 2006, 03:12 PM
  4. Select box form elements error- loop within a loop confusion
    By nickihandy in forum ASP Development
    Replies: 14
    Last Post: October 5th, 2005, 02:25 PM
  5. Repeat loop in email
    By Steve Schofield in forum ASP Development
    Replies: 1
    Last Post: November 14th, 2000, 06:06 AM

IMN logo majestic logo threadwatch logo seochat tools logo