Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default ASP Loop question

    Hi Everyone,

    I'm trying to work out how I can include something in a loop for all
    but the final pass. What I'm trying to do exactly is include an image
    (spacer.gif) in a table row to seperate the records, but I do not want
    the image to be included at the bottom of the page. I was thinking
    about using some sort of counter in my loop to determine if it is eof
    then... but I'm not that good at this ASP stuff yet. Ideas??

    Here's what I have so far

    <table>

    <% Do until rs.eof %>
    <tr>
    <td width="20%"><img src="images/<% Response.Write(rs("ProjectName"))
    %>.gif" border=1></td>
    <td width="75%"><% Response.Write(rs("ProjectName")) %><br><%
    Response.Write(rs("ProjectDescription")) %></td>
    <td width="5%">&nbsp;</td>
    </tr>

    <tr>
    <td colspan=3 width="100%" align="center" valign="top"><img
    src="images/spacer3.gif" width="600" height="1"></td>
    </tr>

    <%
    rs.movenext
    loop
    %>

    Thanks in advance :)

    Darren Stahlhut
    Darren Guest

  2. Similar Questions and Discussions

    1. Loop Question
      I am trying to loop through in a javascript expression. Here is the code: <cfloop query ="bannerrotator" startrow="0" endrow="2" index="i"...
    2. if/loop/array question
      I'm trying to display an add or delete button dependent upon logged in user and I can't figure it out. Can someone please help with the...
    3. A loop question?
      Having more problems with updating contacts. For all that responded to my previous problem THANKS. I accidentally deleted the posts so I couldn't...
    4. php conditional loop question
      ok. This is probably simple but I am not thinking straight. Here is what I want to do I have a function that makes a connection to a live...
    5. Fastest FSO loop question
      Well I have seen this posted before and haven't seen much in response. My application has to browse through various folders and find file names....
  3. #2

    Default Re: ASP Loop question

    I suppose you could do:


    If Not rs.EOF Then
    Response.Write YourImageLine '''you want an image above?
    Do
    Response.Write YourRecordsetValueLine
    rs.MoveNext
    If rs.EOF Then Exit Do
    Response.Write YourImageLine
    Loop
    End If

    I don't know that that'd be the most efficient way to do it. A better way
    may be to use .GetRows() and then loop through your array. You could
    prefetch the UBound(theArray, 2) to know when to exit the loop.


    --

    Ray at home
    Microsoft ASP MVP


    "Darren" <darrenstahlhut@hotmail.com> wrote in message
    news:898d00a0.0402022056.3429fc6d@posting.google.c om...
    > Hi Everyone,
    >
    > I'm trying to work out how I can include something in a loop for all
    > but the final pass. What I'm trying to do exactly is include an image
    > (spacer.gif) in a table row to seperate the records, but I do not want
    > the image to be included at the bottom of the page. I was thinking
    > about using some sort of counter in my loop to determine if it is eof
    > then... but I'm not that good at this ASP stuff yet. Ideas??
    >
    > Here's what I have so far
    >
    > <table>
    >
    > <% Do until rs.eof %>
    > <tr>
    > <td width="20%"><img src="images/<% Response.Write(rs("ProjectName"))
    > %>.gif" border=1></td>
    > <td width="75%"><% Response.Write(rs("ProjectName")) %><br><%
    > Response.Write(rs("ProjectDescription")) %></td>
    > <td width="5%">&nbsp;</td>
    > </tr>
    >
    > <tr>
    > <td colspan=3 width="100%" align="center" valign="top"><img
    > src="images/spacer3.gif" width="600" height="1"></td>
    > </tr>
    >
    > <%
    > rs.movenext
    > loop
    > %>
    >
    > Thanks in advance :)
    >
    > Darren Stahlhut

    Ray at Guest

  4. #3

    Default Re: ASP Loop question

    "Darren" <darrenstahlhut@hotmail.com> wrote in message
    news:898d00a0.0402022056.3429fc6d@posting.google.c om...
    > Hi Everyone,
    >
    > I'm trying to work out how I can include something in a loop for all
    > but the final pass. What I'm trying to do exactly is include an image
    > (spacer.gif) in a table row to seperate the records, but I do not want
    > the image to be included at the bottom of the page. I was thinking
    > about using some sort of counter in my loop to determine if it is eof
    > then... but I'm not that good at this ASP stuff yet. Ideas??

    How about inserting the image before each row except the first?


    McKirahan Guest

  5. #4

    Default Re: ASP Loop question


    "Darren" <darrenstahlhut@hotmail.com> wrote in message
    news:898d00a0.0402022056.3429fc6d@posting.google.c om...
    > Hi Everyone,
    >
    > I'm trying to work out how I can include something in a loop for all
    > but the final pass. What I'm trying to do exactly is include an image
    > (spacer.gif) in a table row to seperate the records, but I do not want
    > the image to be included at the bottom of the page. I was thinking
    > about using some sort of counter in my loop to determine if it is eof
    > then... but I'm not that good at this ASP stuff yet. Ideas??
    >
    > Here's what I have so far
    >
    > <table>
    >
    > <% Do until rs.eof %>
    > <tr>
    > <td width="20%"><img src="images/<% Response.Write(rs("ProjectName"))
    > %>.gif" border=1></td>
    > <td width="75%"><% Response.Write(rs("ProjectName")) %><br><%
    > Response.Write(rs("ProjectDescription")) %></td>
    > <td width="5%">&nbsp;</td>
    > </tr>
    >
    > <tr>
    > <td colspan=3 width="100%" align="center" valign="top"><img
    > src="images/spacer3.gif" width="600" height="1"></td>
    > </tr>
    >
    > <%
    > rs.movenext
    > loop
    > %>
    >
    > Thanks in advance :)
    >
    > Darren Stahlhut
    Hi Darren,
    A word of advice: Quit using rs.eof. Use arrayvar = rs.GetRows()
    There are lots of discussions on how to do this. Do a Google, or DevDex
    search.
    Basically array(column number, row number).

    Then loop until UBound(arrayvar)
    The loop is v. simple:
    <TABLE>
    Dim a_Rows, i_Row, i_NumRows
    If Not rs.EOF Then
    a_Rows = rs.GetRows
    i_NumRows = UBound(a_Rows, 2)
    End If
    For i_Row = 0 To i_NumRows
    THINGS HERE WILL APPEAR IN EVERY CYCLE
    If i_Row <> i_NumRows Then
    THINGS IN HERE WON'T APPEAR IN THE FINAL CYCLE
    End If
    Next
    </TABLE>

    Apologies for any errors.

    HTH

    Matt Smith


    Matt Smith Guest

  6. #5

    Default Re: ASP Loop question

    "Matt Smith" <crap@spam.com> wrote in message news:<bvo9p5$6k5$1@sparta.btinternet.com>...
    > "Darren" <darrenstahlhut@hotmail.com> wrote in message
    > news:898d00a0.0402022056.3429fc6d@posting.google.c om...
    > > Hi Everyone,
    > >
    > > I'm trying to work out how I can include something in a loop for all
    > > but the final pass. What I'm trying to do exactly is include an image
    > > (spacer.gif) in a table row to seperate the records, but I do not want
    > > the image to be included at the bottom of the page. I was thinking
    > > about using some sort of counter in my loop to determine if it is eof
    > > then... but I'm not that good at this ASP stuff yet. Ideas??
    > >
    > > Here's what I have so far
    > >
    > > <table>
    > >
    > > <% Do until rs.eof %>
    > > <tr>
    > > <td width="20%"><img src="images/<% Response.Write(rs("ProjectName"))
    > > %>.gif" border=1></td>
    > > <td width="75%"><% Response.Write(rs("ProjectName")) %><br><%
    > > Response.Write(rs("ProjectDescription")) %></td>
    > > <td width="5%">&nbsp;</td>
    > > </tr>
    > >
    > > <tr>
    > > <td colspan=3 width="100%" align="center" valign="top"><img
    > > src="images/spacer3.gif" width="600" height="1"></td>
    > > </tr>
    > >
    > > <%
    > > rs.movenext
    > > loop
    > > %>
    > >
    > > Thanks in advance :)
    > >
    > > Darren Stahlhut
    > Hi Darren,
    > A word of advice: Quit using rs.eof. Use arrayvar = rs.GetRows()
    > There are lots of discussions on how to do this. Do a Google, or DevDex
    > search.
    > Basically array(column number, row number).
    >
    > Then loop until UBound(arrayvar)
    > The loop is v. simple:
    > <TABLE>
    > Dim a_Rows, i_Row, i_NumRows
    > If Not rs.EOF Then
    > a_Rows = rs.GetRows
    > i_NumRows = UBound(a_Rows, 2)
    > End If
    > For i_Row = 0 To i_NumRows
    > THINGS HERE WILL APPEAR IN EVERY CYCLE
    > If i_Row <> i_NumRows Then
    > THINGS IN HERE WON'T APPEAR IN THE FINAL CYCLE
    > End If
    > Next
    > </TABLE>
    >
    > Apologies for any errors.
    >
    > HTH
    >
    > Matt Smith

    Thanks everyone,

    Matt, although your way might be better, it also looks very
    complicated for a newbie like me. I'll investigate the use of UBound
    and rs.GetRows for future pages. Ray, your way sounds good too, but I
    think I will used McKirahan's idea.

    I'm pretty sure I can get it to work by putting the image above all of
    the rows except the first one by using a count. IE. If count > 0
    then...

    Thanks again for all your help :)

    Darren Stahlhut
    Darren Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139