looping with asp

B

Billy Barth

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%>
 
B

Bob Barrows [MVP]

Billy said:
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.
 
G

GeorgeScott

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
 
B

Bob Lehmann

**********************************************
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top