Forum Moderators: open
I'm still in my learning stages so I'm sure what I have is simple to figure out but I can't seem to. When I try to use an if statement during the loop my response comes back however many entries I have. For example: two enrollees brings back two responses, or more if the class is already full. It should only bring a response to enroll if there are openings.
Here's my code:
<%
response.write "<tr><td class=head>Branch/Department</td><td></td><td class=head>Name</td><td></td><td class=head>Title</td><td></td><td class=head>Ext</td></tr>"
%>
<% DO WHILE NOT rstemp.eof
classdate=rstemp("classDate")
' put fields into variables
' enrollid=rstemp("enrollID")
classid=rstemp("classID")
name=rstemp("name")
ext=rstemp("ext")
dept=rstemp("dept")
title=rstemp("title")
enrolled=rstemp("enrolled")
if not isNumeric(enrolled) then enrolled = 0
maxenroll=rstemp("maxEnroll")
openslots = maxenroll - enrolled
'if enrolled < maxenroll then response.write "test"
' write the fields to browser
response.write "<tr class=view><td width=180> "& rstemp("dept") & "</td><td width=10> </td><td width=170> "& rstemp("name") & "</td><td width=10> </td><td width=120>"& rstemp("title") & "</td><td width=10> </td><td width=100>"& rstemp("ext") & "</td></tr>"
rstemp.movenext
LOOP
%>
<TR>
<TD> </td>
<td>
<% if enrolled < maxenroll then %>
<a href="enroll.asp?classID=<%=rstemp("classID")%>&className=<%=Escape(classname)%>&classDate=<%=classdate%>">
Enroll</a>
<% else %>
Go back to Training
<% end if %>
</td>
</TR>
here are the modified code:
<%
response.write "<tr><td class=head>Branch/Department</td><td></td><td class=head>Name</td><td></td><td class=head>Title</td><td></td><td class=head>Ext</td></tr>"
%>
<% DO WHILE NOT rstemp.eof
classdate=rstemp("classDate")
' put fields into variables
' enrollid=rstemp("enrollID")
classid=rstemp("classID")
name=rstemp("name")
ext=rstemp("ext")
dept=rstemp("dept")
title=rstemp("title")
enrolled=rstemp("enrolled")
if not isNumeric(enrolled) then enrolled = 0
maxenroll=rstemp("maxEnroll")
openslots = maxenroll - enrolled
if enrolled < maxenroll then
%>
<tr class=view>
<td width=180> <%= rstemp("dept")%> <a href="enroll.asp?classID=<%=rstemp("classID")%>&className=<%=Escape(classname)%>&classDate=<%=classdate%>">
Enroll</a>
</td>
<td width=10> </td>
<td width=170> <%=rstemp("name") %></td>
<td width=10> </td>
<td width=120><%= rstemp("title")%></td>
<td width=10> </td>
<td width=100><%=rstemp("ext")%></td>
</tr>
<%else%>
<tr class=view>
<td width=180> <%= rstemp("dept")%></td>
<td width=10> </td>
<td width=170> <%=rstemp("name") %></td>
<td width=10> </td>
<td width=120><%= rstemp("title")%></td>
<td width=10> </td>
<td width=100><%=rstemp("ext")%></td>
</tr>
<%
end if
rstemp.movenext
LOOP
%>