I need to loop through my SQL Server datatable and display some information on each record. However, I need to group this by the same start times for each "event". I'd like to do this in one loop command and not a separate loop command for each time. I know it's probably something simple that I'm missing. But I can't figure it out. I'd like to group these events by start time. I'd like to have an H4 header for each start time and show all events for that start time and then move onto the next start time with an H4 tag as well. But only one H4 tag for each groups of start times. Here is my code:
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open
strSQL = "SELECT EventTitle, FinalStartTime, FinalEndTime, Organization, description FROM Meetings WHERE ApprovalStatus = 'Approved' ORDER BY FinalStartTime"
Set rstDisplay = Conn.Execute(strSQL)
i=0
While Not rstDisplay.EOF
i=i+1
strSecondStartTime = strStartTime
strStartTime = rstDisplay("FinalStartTime")
strEndTime = rstDisplay("FinalEndTime")
%>
<h4><%=strStartTime%>–<%=strEndTime%></h4>
<table class="prog-table" id="report<%=i%>">
<tr>
<td class="firsttd"><%=rstDisplay("EventTitle")%><span style="float:right; opacity:0.5; display:block; padding-left:50px;"><i class="fa fa-plus" aria-hidden="true"></i></span></td>
</tr>
<tr>
<td>
<p><strong>Presented by:</strong><BR>
<blockquote><%=rstDisplay("Organization")%></blockquote></p>
<p><%=rstDisplay("description")%></p>
</td>
</tr>
</table>
<%
rstDisplay.MoveNext
Wend
rstDisplay.Close
Conn.Close
%>
The resulting HTML should be in simplified terms:
9:00 AM - 10:00 AM
Event 1
Event 2
11:00 AM - 12:00 PM
Event 3
Event 4
1:00 PM - 2:00 PM
Event 5
3:00 PM - 4:00 PM
Event 6
Event 7
Event 8
Currently my resulting HTML is incorrect and is displaying as such:
9:00 AM - 10:00 AM
Event 1
9:00 AM - 10:00 AM
Event 2
9:00 AM - 10:00 AM
Event 3
etc, etc.