looping with asp

Discussion in 'ASP General' started by Billy Barth, Jun 8, 2007.

  1. Billy Barth

    Billy Barth Guest

    I am trying to loop through my database to display a picture. That is
    no problem. Where I hit a snag is this. I only want three pictures
    then break to a new row and three more, etc. Any ideas?
    What this does is display one record. Any Help would be appreciated
    Below is my code.

    <%
    strSQL="SELECT DISTINCT Kids.kids_Id AS Kids, kids_pics.kids_ID AS
    kids_pics_kids_ID,pic_name,first_Name,kids_Desc,kids_Age FROM Kids
    INNER JOIN kids_pics ON Kids.kids_Id = kids_pics.kids_ID "
    Set rsk = CreateObject("ADODB.Recordset")
    rsk.Open strSQL, con, adOpenStatic, adLockReadOnly
    %>

    <h1>Waiting Children</h1>

    <%
    count=count+1
    if rsk.eof then error
    if not rsk.eof and count>=3 then
    count=0%>error
    <%else%>
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td align="center" width="81"><img src="images/kids_photos/<
    %=rsk("pic_name")%>" alt="Featured Child" /></td>
    </tr>
    <tr>
    <td align="center" width="81"><%=rsk("first_Name")%></td>
    </tr></table>
    <%end if%>
     
    Billy Barth, Jun 8, 2007
    #1
    1. Advertising

  2. Billy Barth wrote:
    > I am trying to loop through my database to display a picture. That is


    This seems to be a duplicate of a previous post. In that thread, you told
    John that his suggested solution worked, so either:

    This post was inadvertant
    or
    You've run into a problem with John's solution, in which case you should
    have replied in the original thread.

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Jun 8, 2007
    #2
    1. Advertising

  3. Billy Barth

    GeorgeScott Guest

    On Jun 8, 2:16 am, Billy Barth <> wrote:
    > I am trying to loop through my database to display a picture. That is
    > no problem. Where I hit a snag is this. I only want three pictures
    > then break to a new row and three more, etc. Any ideas?
    > What this does is display one record. Any Help would be appreciated
    > Below is my code.
    >
    > <%
    > strSQL="SELECT DISTINCT Kids.kids_Id AS Kids, kids_pics.kids_ID AS
    > kids_pics_kids_ID,pic_name,first_Name,kids_Desc,kids_Age FROM Kids
    > INNER JOIN kids_pics ON Kids.kids_Id = kids_pics.kids_ID "
    > Set rsk = CreateObject("ADODB.Recordset")
    > rsk.Open strSQL, con, adOpenStatic, adLockReadOnly
    > %>
    >
    > <h1>Waiting Children</h1>
    >
    > <%
    > count=count+1
    > if rsk.eof then error
    > if not rsk.eof and count>=3 then
    > count=0%>error
    > <%else%>
    > <table border="0" cellspacing="0" cellpadding="0">
    > <tr>
    > <td align="center" width="81"><img src="images/kids_photos/<
    > %=rsk("pic_name")%>" alt="Featured Child" /></td>
    > </tr>
    > <tr>
    > <td align="center" width="81"><%=rsk("first_Name")%></td>
    > </tr></table>
    > <%end if%>



    Rs Movenext is really old slow code, but I just happen to have some
    hanging around so here goes


    You need to make table go to the next row every 3 images try this be
    sure to add Count = 0 at the top of your code above your sql string
    then add this (change to make it work for you) to your loop.


    if Count = "4" then response.write "</tr><tr>"
    if Count = "8" then response.write "</tr><tr>"
    if Count = "12" then response.write "</tr><tr>"
    if Count = "16" then response.write "</tr><tr>"

    rs.MoveNext
    Count = Count + 1
    Loop
    Rs.Close

    'This is faster code to do the same thing. Rs.MoveNext beats the
    database up going to the DB for every row. This gets all the rows and
    puts them into an array

    'Get pictures from DB and display on page
    strSQL="SELECT DISTINCT Kids.kids_Id AS Kids, kids_pics.kids_ID AS
    kids_pics_kids_ID,pic_name,first_Name,kids_Desc,kids_Age FROM Kids
    INNER JOIN kids_pics ON Kids.kids_Id = kids_pics.kids_ID "
    Set rsk = CreateObject("ADODB.Recordset")
    rsk.Open strSQL, con, adOpenStatic, adLockReadOnly
    if not rsk.Eof then
    aryPictures = Rsk.GetRows
    bDisplay=True
    else
    response.write "No Pictures Found"
    end if
    rsk.Close

    'dim aryPictures' as an array of strings and ints
    'aryPictures (0, iRowLoop) = kids_Id
    'aryPictures (1, iRowLoop) = kids_pics_kids_ID
    'aryPictures (2, iRowLoop) = pic_name
    'aryPictures (3, iRowLoop) = first_Name
    'aryPictures (3, iRowLoop) = kids_Desc
    'aryPictures (3, iRowLoop) = kids_Age

    if bDisplay=True then
    response.write "<table>"
    For iRowLoop = 0 to UBound(aryPictures , 2)

    response.write "<tr></td>"
    response.write aryPictures (0, iRowLoop)
    response.write aryPictures (1, iRowLoop)
    response.write aryPictures (2, iRowLoop)
    response.write aryPictures (3, iRowLoop)
    response.write aryPictures (4, iRowLoop)
    response.write aryPictures (5, iRowLoop)
    response.write "</td>"

    if iRowLoop = 3 then response.write "</tr>"
    if iRowLoop = 6 then response.write "</tr>"
    if iRowLoop = 9 then response.write "</tr>"
    if iRowLoop = 12 then response.write "</tr>"

    Next
    response.write "</table>"

    end if

    George Scott
    www.officezilla.com
     
    GeorgeScott, Jun 14, 2007
    #3
  4. Billy Barth

    Bob Lehmann Guest

    **********************************************
    if Count = "4" then response.write "</tr><tr>"
    if Count = "8" then response.write "</tr><tr>"
    if Count = "12" then response.write "</tr><tr>"
    if Count = "16" then response.write "</tr><tr>"

    **********************************************

    Or you could write one line of code that will last forever, no matter how
    many rows are added............

    if Count Mod 4 = 0 then response.write "</tr><tr>"

    Bob Lehmann

    "GeorgeScott" <> wrote in message
    news:...
    > On Jun 8, 2:16 am, Billy Barth <> wrote:
    > > I am trying to loop through my database to display a picture. That is
    > > no problem. Where I hit a snag is this. I only want three pictures
    > > then break to a new row and three more, etc. Any ideas?
    > > What this does is display one record. Any Help would be appreciated
    > > Below is my code.
    > >
    > > <%
    > > strSQL="SELECT DISTINCT Kids.kids_Id AS Kids, kids_pics.kids_ID AS
    > > kids_pics_kids_ID,pic_name,first_Name,kids_Desc,kids_Age FROM Kids
    > > INNER JOIN kids_pics ON Kids.kids_Id = kids_pics.kids_ID "
    > > Set rsk = CreateObject("ADODB.Recordset")
    > > rsk.Open strSQL, con, adOpenStatic, adLockReadOnly
    > > %>
    > >
    > > <h1>Waiting Children</h1>
    > >
    > > <%
    > > count=count+1
    > > if rsk.eof then error
    > > if not rsk.eof and count>=3 then
    > > count=0%>error
    > > <%else%>
    > > <table border="0" cellspacing="0" cellpadding="0">
    > > <tr>
    > > <td align="center" width="81"><img src="images/kids_photos/<
    > > %=rsk("pic_name")%>" alt="Featured Child" /></td>
    > > </tr>
    > > <tr>
    > > <td align="center" width="81"><%=rsk("first_Name")%></td>
    > > </tr></table>
    > > <%end if%>

    >
    >
    > Rs Movenext is really old slow code, but I just happen to have some
    > hanging around so here goes
    >
    >
    > You need to make table go to the next row every 3 images try this be
    > sure to add Count = 0 at the top of your code above your sql string
    > then add this (change to make it work for you) to your loop.
    >
    >
    > if Count = "4" then response.write "</tr><tr>"
    > if Count = "8" then response.write "</tr><tr>"
    > if Count = "12" then response.write "</tr><tr>"
    > if Count = "16" then response.write "</tr><tr>"
    >
    > rs.MoveNext
    > Count = Count + 1
    > Loop
    > Rs.Close
    >
    > 'This is faster code to do the same thing. Rs.MoveNext beats the
    > database up going to the DB for every row. This gets all the rows and
    > puts them into an array
    >
    > 'Get pictures from DB and display on page
    > strSQL="SELECT DISTINCT Kids.kids_Id AS Kids, kids_pics.kids_ID AS
    > kids_pics_kids_ID,pic_name,first_Name,kids_Desc,kids_Age FROM Kids
    > INNER JOIN kids_pics ON Kids.kids_Id = kids_pics.kids_ID "
    > Set rsk = CreateObject("ADODB.Recordset")
    > rsk.Open strSQL, con, adOpenStatic, adLockReadOnly
    > if not rsk.Eof then
    > aryPictures = Rsk.GetRows
    > bDisplay=True
    > else
    > response.write "No Pictures Found"
    > end if
    > rsk.Close
    >
    > 'dim aryPictures' as an array of strings and ints
    > 'aryPictures (0, iRowLoop) = kids_Id
    > 'aryPictures (1, iRowLoop) = kids_pics_kids_ID
    > 'aryPictures (2, iRowLoop) = pic_name
    > 'aryPictures (3, iRowLoop) = first_Name
    > 'aryPictures (3, iRowLoop) = kids_Desc
    > 'aryPictures (3, iRowLoop) = kids_Age
    >
    > if bDisplay=True then
    > response.write "<table>"
    > For iRowLoop = 0 to UBound(aryPictures , 2)
    >
    > response.write "<tr></td>"
    > response.write aryPictures (0, iRowLoop)
    > response.write aryPictures (1, iRowLoop)
    > response.write aryPictures (2, iRowLoop)
    > response.write aryPictures (3, iRowLoop)
    > response.write aryPictures (4, iRowLoop)
    > response.write aryPictures (5, iRowLoop)
    > response.write "</td>"
    >
    > if iRowLoop = 3 then response.write "</tr>"
    > if iRowLoop = 6 then response.write "</tr>"
    > if iRowLoop = 9 then response.write "</tr>"
    > if iRowLoop = 12 then response.write "</tr>"
    >
    > Next
    > response.write "</table>"
    >
    > end if
    >
    > George Scott
    > www.officezilla.com
    >
     
    Bob Lehmann, Jun 15, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWljaGFlbA==?=

    ASP.NET Looping in Application_Error handler

    =?Utf-8?B?TWljaGFlbA==?=, Jun 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    535
    =?Utf-8?B?TWljaGFlbA==?=
    Jun 16, 2004
  2. =?Utf-8?B?TWljaGFlbA==?=

    ASP.NET looping in the Application_Error handler

    =?Utf-8?B?TWljaGFlbA==?=, Jun 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    321
    =?Utf-8?B?TWljaGFlbA==?=
    Jun 21, 2004
  3. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: ASP.NET looping in the Application_Error handler

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    511
    Phil Winstanley [Microsoft MVP ASP.NET]
    Jun 21, 2004
  4. ML
    Replies:
    1
    Views:
    866
  5. Replies:
    5
    Views:
    289
Loading...

Share This Page