Click to See Complete Forum and Search --> : Loops


jrthor2
07-14-2003, 01:12 PM
I have a database of schedules. I want my page to show different tables with headings depending on the value in the category field. I have it set up, but it is printing a new table for each result it finds. I want it to display a table with the category as the heading and then all the rows with that category in the rows below the heading. Here is the code for the first category I want to filter.

<%
Dim rs
Dim conn
Dim SQLstmt
Dim DSNtemp

Set conn = server.createobject("adodb.connection")
DSNtemp="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/db/schedules.mdb")
conn.Open DSNtemp

SQLstmt = "SELECT * from Schedules order by begin_dte desc, [time] desc"
'Response.Write(SQLstmt)
Set rs = conn.execute(SQLstmt)
%>
<%

x=0
Dim iRecordCount,mycolor
iRecordCount = 0
Do while Not rs.EOF
mycolor = "#ffffff"
If mycolor = "#ffffff" Then
mycolor = "#d7d7ff"
Else
mycolor = "#ffffff"
End If
id = rs("ID")
begin_dte = rs("BEGIN_DTE")
end_dte = rs("END_DTE")
category = rs("CATEGORY")
strtime = rs("TIME")
strname = rs("NAME")

If (category) = "Acolytes" Then
%>
<TABLE width="70%" cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TD noWrap bgColor=330099 height=15 rowSpan=2>
<FONT face=verdana
color=white size=-2>&nbsp;&nbsp;<B>Acolyte Schedule</B></FONT></TD>
<TD height="15" vAlign=top><IMG height=15 alt=""
src="/images/tr14x15_1.gif" width=14></TD>
</TR>
</TBODY>
</TABLE>
<table width="100%" border="1" cellspacing="0" cellpadding="5" bordercolor="330099" bgcolor="#FFFFFF">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" align="center" width="100%">
<tr>
<td><u><strong>Date</strong></u></td>
<td><u><strong>Time</strong></u></td>
<td><u><strong>Name</strong></u></td>
</tr>
<tr bgcolor="<%=mycolor%>">
<td>
<%=begin_dte%>
</td>
<td><%=strtime%></td>
<td><%=strname%></td>
</tr>
</table>
</td>
</tr>
</table>
<% End if %>
<br>
<% If (category) = "Altar Guild" Then %>
<% End if %>
<% If (category) = "Coffee" Then %>
<% End If %>
<% If (category) = "Nursery" Then %>
<% End If %>
<% If (category) = "Lector/Lay Assistants" Then %>
<% End if %>
<% If (category) = "Ushers" Then %>
<% End If %>
<% If (category) = "Flower Delivery" Then %>
<% end If %>
<%
iRecordCount = iRecordCount + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set conn = Nothing
Set SQLstmt = Nothing
%>

jrthor2
07-15-2003, 08:27 AM
Yeah, I just got it fixed 5 min ago. Thanks though!!