Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > looping with asp

Reply
Thread Tools

looping with asp

 
 
Billy Barth
Guest
Posts: n/a
 
      06-08-2007
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,ki ds_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%>

 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      06-08-2007
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"


 
Reply With Quote
 
 
 
 
GeorgeScott
Guest
Posts: n/a
 
      06-14-2007
On Jun 8, 2:16 am, Billy Barth <(E-Mail Removed)> 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,ki ds_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,ki ds_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

 
Reply With Quote
 
Bob Lehmann
Guest
Posts: n/a
 
      06-14-2007
**********************************************
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> On Jun 8, 2:16 am, Billy Barth <(E-Mail Removed)> 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,ki ds_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,ki ds_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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
looping in array vs looping in a dic giuseppe.amatulli@gmail.com Python 5 09-20-2012 11:58 PM
Handling large batch looping database update process from ASP.NET page? ML ASP .Net 1 08-16-2005 10:03 AM
Re: ASP.NET looping in the Application_Error handler Phil Winstanley [Microsoft MVP ASP.NET] ASP .Net 0 06-21-2004 03:09 PM
ASP.NET looping in the Application_Error handler =?Utf-8?B?TWljaGFlbA==?= ASP .Net 0 06-21-2004 02:37 PM
ASP.NET Looping in Application_Error handler =?Utf-8?B?TWljaGFlbA==?= ASP .Net 0 06-16-2004 02:25 PM



Advertisments