?
Solved

if rs.EOF trouble.

Posted on 2003-03-06
11
Medium Priority
?
1,081 Views
Last Modified: 2012-08-14
I have this, it's a page which selects your community friends and lists them if they are online. It works splendid if anyone of them is online but if the recordcount is empty I want to display "No-one online :/" or similar. The thing is, I can't seem to place it correctly! Please just paste my code snip with an if nusa.eof statement.

<%

Dim bColor
bColor = true
     Dim rs, nusa, ar, SQL
 
          SQL = "SELECT * FROM friends WHERE besvarad = 1 and kompis = '" & session("id") & "' or besvarad = 1 and medlem = '" & session("id") & "'"
       
               SET rs = adoConn.Execute(SQL)
       
                    if rs.eof then %>
                    <tr>
                         <td class="cell2" border="0" valign="top">
                              <table border="0" bgcolor="#000000" cellpadding="0" cellspacing="0">
                                   <tr>
                                        <td class="cell2">
                                             &nbsp;<font class="stanlb">Inga vänner :/</font>
                                        </td>
                                   </tr>
                              </table>
                         </td>
                    </tr>
                    <% rs.Close
                         SET rs = Nothing
                              SET adoConn = Nothing
   
               else
   
                         do while not rs.EOF
       
                         SET nusa = adoConn.Execute("SELECT id, user, inloggad, fodd, kon FROM members WHERE id='" & rs("medlem") & "' or id='" & rs("kompis") & "'")
     
                              if nusa("id") = Session("id") then
                              nusa.MoveNext
                              end if
     
                              if nusa("inloggad") <> 1 then
                              nusa.MoveNext
                              else
     
                                   ar = DateDiff("d", nusa("fodd"), date)
                                   ar = ar / 365.25
                                   ar = fix(ar)
     
                    %>
                                        <tr bgcolor="<%If bColor = True Then
                                             Response.Write("#FFFFFF")
                                                  bColor = False
                                   else
                                             Response.Write ("#9FC5F5")
                                                  bColor = True
                                                       End if %>">
                                             <td class="blipp2">
                                                  &nbsp;<a class="info" href="visa.asp?id=<%=nusa("id")%>" target="_parent"><%=nusa("user")%><a>
                                   <% if nusa("kon") = "k" then
                                        response.write "<font class='stanlb'>"  & nusa("kon") & ar & "</font>"
                                      elseif nusa("kon") = "t" then
                                        response.write "<font class='stanlbp'>" & nusa("kon") & ar & "</font>"
                                      end if
                                   %>
                                             </td>
                                        </tr>
                                   <%
   
                                   end if
     
                         rs.Movenext
                         Loop
       
                    rs.Close
                    SET rs = Nothing
       
               nusa.Close
               SET nusa = Nothing
       
          adoConn.Close
          SET adoConn = Nothing
       
      end if      
      %>

And I know there are betters ways to use RecordSets...I'm newbish to this :)
0
Comment
Question by:bobamatics
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 

Expert Comment

by:greddin
ID: 8084074
I didn't see your adoConn string...

Try this:

SQL = "SELECT * FROM friends WHERE besvarad = 1 and kompis = '" & session("id") & "' or besvarad = 1 and medlem = '" & session("id") & "'"

'create a recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

'set the cursor location and type
rs.CursorLocation = 3' adUseClient
rs.CursorType = 3 'adOpenStatic

rs.Open SQL, adoConn

'check if empty
If rs.EOF Then
    Response.Write "No records found!<br>"
Else
'do the rest of your code here...


-Greg
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8084181
SQL = "SELECT Count(*) as numRecs, * FROM friends WHERE besvarad = 1 and kompis = '" & session("id") & "' or besvarad = 1 and medlem = '" & session("id") & "'"


Then later:

               if rs("numRecs")<1 then %>
                   <tr>
                        <td class="cell2" border="0" valign="top">
                             <table border="0" bgcolor="#000000" cellpadding="0" cellspacing="0">
                                  <tr>
                                       <td class="cell2">
                                            &nbsp;<font class="stanlb">Inga vdnner :/</font>
                                       </td>
                                  </tr>
                             </table>
                        </td>
                   </tr>
                   <% rs.Close
                        SET rs = Nothing
                             SET adoConn = Nothing
 
              else


Fritz the Blank
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8084195
Dim bColor
bColor = true
    Dim rs, nusa, ar, SQL
 
         SQL = "SELECT * FROM friends WHERE besvarad = 1 and kompis = '" & session("id") & "' or besvarad = 1 and medlem = '" & session("id") & "'"
     
              SET rs = adoConn.Execute(SQL)
     
                   if rs.eof then %>
                   <tr>
                        <td class="cell2" border="0" valign="top">
                             <table border="0" bgcolor="#000000" cellpadding="0" cellspacing="0">
                                  <tr>
                                       <td class="cell2">
                                            &nbsp;<font class="stanlb">Inga vdnner :/</font>
                                       </td>
                                  </tr>
                             </table>
                        </td>
                   </tr>
                   <% rs.Close
                        SET rs = Nothing
                             SET adoConn = Nothing
 
              else
 
                        do while not rs.EOF
     
                        SET nusa = adoConn.Execute("SELECT id, user, inloggad, fodd, kon FROM members WHERE id='" & rs("medlem") & "' or id='" & rs("kompis") & "'")
                             if nusa.EOF then
                                response.write "No One Present"
                                 response.end
                             end if
   
                             if nusa("id") = Session("id") then
                             nusa.MoveNext
                             end if
   
                             if nusa("inloggad") <> 1 then
                             nusa.MoveNext
                             else
   
                                  ar = DateDiff("d", nusa("fodd"), date)
                                  ar = ar / 365.25
                                  ar = fix(ar)
   
                   %>
                                       <tr bgcolor="<%If bColor = True Then
                                            Response.Write("#FFFFFF")
                                                 bColor = False
                                  else
                                            Response.Write ("#9FC5F5")
                                                 bColor = True
                                                      End if %>">
                                            <td class="blipp2">
                                                 &nbsp;<a class="info" href="visa.asp?id=<%=nusa("id")%>" target="_parent"><%=nusa("user")%><a>
                                  <% if nusa("kon") = "k" then
                                       response.write "<font class='stanlb'>"  & nusa("kon") & ar & "</font>"
                                     elseif nusa("kon") = "t" then
                                       response.write "<font class='stanlbp'>" & nusa("kon") & ar & "</font>"
                                     end if
                                  %>
                                            </td>
                                       </tr>
                                  <%
   
                                  end if
   
                        rs.Movenext
                        Loop
     
                   rs.Close
                   SET rs = Nothing
     
              nusa.Close
              SET nusa = Nothing
     
         adoConn.Close
         SET adoConn = Nothing
     
     end if      
     %>

And I know there are betters ways to use RecordSets...I'm newbish to this :)

hope this helps!

MaxOvrdrv2
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:keystrokes
ID: 8084230
There is nothing wrong with your if rs.eof statement.  Maybe it's not eof eventhough no one is online?  Response.write your sql statement and see if you are getting the correct recordset you are expecting.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8084305
Without reading everyones posted comments thoroughly, why don't you just use a SQL that ask's "WHERE online > 0"?  I see you are parsing records that ask's "WHERE besvarad = 1", try > 0...

Then you can use a simple If..Then on the results;

If rs.EOF Then
    Response.Write "Sorry, no one on-line"
Else
    ' Post the results code
End If

[If I duplicated anyones efforts I appologize, I am under a lot of medications, nasty flu bug...]
0
 

Author Comment

by:bobamatics
ID: 8084693
Ok, I think I misnamed the question. It should be nusa.eof trouble.

I also forgot to say that the Set rs = Server.CreateObject("ADODB.Recordset") is included in another file.

So. The first rs takes out all the records where your member-id is listed in the friends table. But it doesn't know if you're the one who asked (medlem) or the one who was asked to be a friend (kompis). If you have no friends (your member-id isn't found in the rs, it displays so. All good.

But if your id is found, it runs another SQL statement to get the records' member info from the members table. But since it shouldn't output your name since your name will be found, I do:

if nusa("id") = Session("id") then
nusa.MoveNext
end if

where Session("id") is your member id. If it finds your member id, go to next row.

I can't put WHERE inloggad = 1 in the SQL statement since if the member isn't logged in, it can't loop out the stuff later on.

So what I want, is a snip that says "if nusa.eof - that means, no friends of those who were found in the original rs, are online (it skipped over all the records since inloggad wasn't 1 anywhere)".

Thanks for all the replies btw!
   

 
0
 

Author Comment

by:bobamatics
ID: 8084710
Btw, WHERE besvarad = 1 in the first rs just means it should fetch those records that have been replied to and accepted as friends. It shouldn't print out those you want to be friends with.
0
 

Expert Comment

by:greddin
ID: 8084786
What's the relationship between the the table "Friends" and "Members". Does "Members" have a foreign_key assigned to "Friends"? If so, why don't you just do a sql INNER JOIN on both tables. The INNER JOIN returns all rows from both tables where there is a match.

SELECT * FROM friends INNER JOIN members ON friends.keyfield = members.foreign_keyfield
WHERE friends.besvarad = 1 and friends.kompis = '" & session("id") & "' or friends.besvarad = 1 and friends.medlem = '" & session("id") & "'"

Then your recordset would have everything.

-Greg
0
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 200 total points
ID: 8088999
ah ok... here it is:

if nusa("id") = Session("id") then
found=1
nusa.MoveNext
end if

and the same for anything that would tell you if a user (friend) is found... you set the found variable to 1 (TRUE)... and then... once you've gone through the loops that check for those users:

if found<>1 then
response.write "No Friends Online"
response.end 'this is if you would like the rest of the script to stop!
end if

Hope this helps!

MaxOvrdrv2
0
 

Author Comment

by:bobamatics
ID: 8092028
Thanks MaxOvrdrv2! :D

I made a slight modification to your solution and came up with this:

after the looped out information: found=1

rs.Movenext
Loop
                         
if found<>1 then
response.write "&nbsp;<font class='stanlb'>No friends online :/</font>"
end if

It works :)
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 8102914
no problem! i'm glad i could help you out! :D

MaxOvrdrv2
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question