looping with asp
am 08.06.2007 11:16:44 von 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
%>
Waiting Children
<%
count=count+1
if rsk.eof then error
if not rsk.eof and count>=3 then
count=0%>error
<%else%>
" alt="Featured Child" /> |
<%=rsk("first_Name")%> |
<%end if%>
Re: looping with asp
am 15.06.2007 00:04:11 von GeorgeScott
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
> %>
>
> Waiting Children
>
> <%
> count=count+1
> if rsk.eof then error
> if not rsk.eof and count>=3 then
> count=0%>error
> <%else%>
>
>
> " alt="Featured Child" /> |
>
>
> <%=rsk("first_Name")%> |
>
> <%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 ""
if Count = "8" then response.write "
"
if Count = "12" then response.write "
"
if Count = "16" then response.write "
"
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 ""
For iRowLoop = 0 to UBound(aryPictures , 2)
response.write ""
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 ""
if iRowLoop = 3 then response.write "
"
if iRowLoop = 6 then response.write ""
if iRowLoop = 9 then response.write ""
if iRowLoop = 12 then response.write ""
Next
response.write "
"
end if
George Scott
www.officezilla.com
Re: looping with asp
am 15.06.2007 01:36:44 von Bob Lehmann
**********************************************
if Count = "4" then response.write "
"
if Count = "8" then response.write "
"
if Count = "12" then response.write "
"
if Count = "16" then response.write "
"
**********************************************
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 "
"
Bob Lehmann
"GeorgeScott" wrote in message
news:1181858651.170070.10980@g37g2000prf.googlegroups.com...
> 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
> > %>
> >
> > Waiting Children
> >
> > <%
> > count=count+1
> > if rsk.eof then error
> > if not rsk.eof and count>=3 then
> > count=0%>error
> > <%else%>
> >
> >
> > " alt="Featured Child" /> |
> >
> >
> > <%=rsk("first_Name")%> |
> >
> > <%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 "
"
> if Count = "8" then response.write "
"
> if Count = "12" then response.write "
"
> if Count = "16" then response.write "
"
>
> 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 ""
> For iRowLoop = 0 to UBound(aryPictures , 2)
>
> response.write ""
> 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 ""
>
> if iRowLoop = 3 then response.write "
"
> if iRowLoop = 6 then response.write ""
> if iRowLoop = 9 then response.write ""
> if iRowLoop = 12 then response.write ""
>
> Next
> response.write "
"
>
> end if
>
> George Scott
> www.officezilla.com
>
Re: looping with asp
am 16.06.2007 17:15:25 von Dave Anderson
"Bob Lehmann" wrote:
> **********************************************
> if Count = "4" then response.write "
"
> if Count = "8" then response.write "
"
> if Count = "12" then response.write "
"
> if Count = "16" then response.write "
"
>
> **********************************************
>
> 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 "
"
Since the OP stated that he wanted three per row, I would go with
If Count Mod 3 = 0 Then ...
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.