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!

Am I missing something in this loop?

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
I have this code
Code:
    <% Do while not (rs.eof or rs.bof) 
    dim conid : conid = rs("contact_id")%>
     <li><a href="[URL unfurl="true"]https://mylink.org/register/ministry.asp"[/URL] onclick="setCookie('contact_id','<%=conid%>')"><%=rs("name_first") %>&nbsp;<%=rs("name_last") %></a>&nbsp;<%=rs("position") %>&nbsp;<%=rs("email") %>&nbsp;<%=rs("cell_phone") %>&nbsp;<%=rs("work_phone")%>&nbsp; If this information is incorrect, then you can edit your info <a href="editcontact.asp?conid=<%=conid %>">here</a>.</li>
    <%rs.MoveNext
    Loop %>
which loops thru just fine, but when there is nothing in the recordset, it still shows the hardcoded text, including the link on the word here. What am I missing here, can anybody out there give me a hand?

Thanks,
WB
 
Yes. It should still show the hardcoded text. That is what you have told it to do.

Think about something like this:

Code:
<%
'I think it is better to dim once and outside any loop
dim conid

'check to see that the sql returned valid records
if rs.eof then
response.write &quot;whatever you want when there are no records&quot;

else

'do your loop
Do while not rs.eof
conid = rs(&quot;contact_id&quot;)
%>

<li>
<a href="[URL unfurl="true"]https://mylink.org/register/ministry.asp"[/URL] onclick="setCookie('contact_id','<%=conid%>')"><%=rs(&quot;name_first&quot;) %>&nbsp;<%=rs(&quot;name_last&quot;) %></a>&nbsp;<%=rs(&quot;position&quot;) %>&nbsp;<%=rs(&quot;email&quot;) %>&nbsp;<%=rs(&quot;cell_phone&quot;) %>&nbsp;<%=rs(&quot;work_phone&quot;)%>&nbsp; If this information is incorrect, then you can edit your info <a href="editcontact.asp?conid=<%=conid %>">here</a>.
</li>
<%
rs.MoveNext
Loop

'get out of the if
end if
%>
 
So, I tried your suggestion and it STILL didn't work as I wanted it to. Then I looked at my query again and realized I am using it to return data for two different areas, one of which will ALWAYS have at least one record, just not the one I am using at this point on the page... Separating that query out took care of my issue. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top