Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm sure this is a simple. Either BOF or EOF is True line 0... 1

Status
Not open for further replies.

ro6er

Programmer
Jul 1, 2003
76
Maybe it's because it's friday but this should work and it doesn't, it's probably something simple right? I should be able to run a simple query in a loop but for some reason I can't.. Here's my code:

<!--#include file="database.asp"-->
<!--#include file="homeheader.asp"-->
<link rel="stylesheet" href="style.css" media="all" type="text/css"/>
<%

mySQL = "SELECT * FROM users"
Set rs = Conn.Execute(mySQL)

Do While Not rs.EOF%>

<div class="thumbs2">
<%


response.write rs("fullname")
if rs("Locked") = "1" then
%>
<img src="images/padlock.jpg" alt="lock" />
<%else%>
<%end if%>
<br />
<%
mySQL = "SELECT * FROM Photos where AlbumCover = ""1"" AND fullname = '"&rs("fullname")&"'"

Set rsPhotos = Conn.Execute(mySQL)
%>
<a href="#">

<img src="thumbs/<%=rsPhotos("PhotoName")%>" />

</a>
</div>
<%
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
%>
 
Sure. You can run a query in a loop. I don't recommend it, but it's certainly possible.

It's also possible that you have a user (in the users table) without a corresponding row in the Photos table where AlbumCover = 1.

When you retrieve data from a query, you should ALWAYS make sure there is an active record before using it. It's simple to do, and will save you lot's of frustration. Specifically, you should modify your code like this:

Code:
  mySQL = "SELECT * FROM Photos where AlbumCover = ""1"" AND fullname = '"&rs("fullname")&"'"

  Set rsPhotos = Conn.Execute(mySQL)
  [!]If Not rsPhotos.Eof[/!]
      %>
      <a href="#">
      <img src="thumbs/<%=rsPhotos("PhotoName")%>" />
      </a>
  [!]<% End If %>[/!]

Of course, we should also have a little discussion regarding the loop. Clearly, you cannot eliminate loops in your code. But... most of the time spent creating web pages occurs within a loop, so it is in your best interest to minimize the work that occurs inside the loop. In this case, you are going to the database inside the loop, and I would suggest that you don't need to.

Of course, you still need to get the data from the database, but you can do this all in one query by using a left join (and putting the AlbumCover condition in the join clause). Like this:

Code:
<!--#include file="database.asp"-->
<!--#include file="homeheader.asp"-->

<link rel="stylesheet" href="style.css" media="all" type="text/css"/>
  <%

  mySQL =         "SELECT users.fullname, users.locked, Coalesce(photos.PhotoName, '') As PhotoName "
  mySQL = mySQL & "FROM   users Left Join Photos "
  mySQL = mySQL & "         On users.FullName = Photos.FullName "
  mySQL = mySQL & "         And Photos.AlbumCover = 1
		
  Set rs = Conn.Execute(mySQL)

  Do While Not rs.EOF%>
    <div class="thumbs2">
      <%
      response.write rs("fullname")
      if rs("Locked") = "1" then
        %>
        <img src="images/padlock.jpg" alt="lock" />
      <%else%>
      <%end if%>

      <br />

      <%
      If rs("PhotoName") <> "" Then
        %>
        <a href="#">
          <img src="thumbs/<%=rsPhotos("PhotoName")%>" />
        </a>
      <% End If %>
    </div>    
    <%
    rs.MoveNext
  Loop
  rs.Close
  Set rs = Nothing
  Conn.Close
  Set Conn = Nothing
%>


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Nice one thanks. I was just looking into a loop. That works fine.

Thanks again Roger
 
[cough] There is place where you could give George a star [cough]
 
Thanks BigRed. But that's not really necessary. Roger's thanks is enough for me.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I've give George a star -

I hate coming into threads only to realize that it has already been solved. The star on the listings page lets me know that someone has already taken care of it.



--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top