emozley
08-19-2005, 03:30 PM
Hi,
I am attempting to write a page which creates an HTML table 1 column wide and with enough rows in to cover the time period 8am to 6pm divided into half hour slots. I also have a database that has 4 main columns - StartTime, EndTime, RoomID and Date. It contains information about whether a boardroom has been booked for use. The idea is the table is being drawn if the room is in use at that point the background is yellow and if it's not the background is white. If a boardroom is in use for say 2 hours I would want all 4 rows to be yellow - not just the first and last ones.
I am running into two problems - 1 how to handle a case where it looks up something in the database and there's nothing there. Either it crashes out or it doesn't complete the table. Even if the room isn't being used all day I would still want to show the table. The second is more of a semantics problem - when I try to compare the time in the row of the table with the time in the recordset it doesn't seem to work properly. Maybe it's because I have inadvertently converted them to strings rather than time values...I'm not sure!
Anyway this is what I've got so far - would be very grateful for any assistance! Thanks:
<%
Set DB = Server.CreateObject("ADODB.Connection")
Set TBL = Server.CreateObject("ADODB.RecordSet")
DB.Mode = adModeReadWrite
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("../directory/userdb.mdb"))
TBL.Open "SELECT StartTime, EndTime FROM Bookings WHERE Date=#" & Date & "# AND RoomID=" & Request.QueryString("Room") & " ORDER BY StartTime ASC", DB
%>
<HTML>
<BODY>
<font face="verdana" size="3">
<b>Schedule for Today - Boardroom <% = Request.QueryString("Room")+1 %></b><br><br>
<table width="100%" cellspacing="5" cellpadding="5" border="1">
<%
Clock=#08:00#
Do While Clock < #18:30#
If Not TBL.EOF Then
StartTime = "#" & TBL("StartTime") & "#"
EndTime = "#" & TBL("EndTime") & "#"
If Clock >= StartTime AND Clock < EndTime Then
Do While Clock < EndTime
Response.Write("<tr>")
Response.Write("<td")
Response.Write(" bgcolor='FFFFCC'>")
Response.Write("</td>")
Response.Write(Clock)
Response.Write("</tr>")
Clock = Clock + #0:30#
Loop
Else
Response.Write("<tr><td>")
Response.Write(Clock)
Response.Write("</td></tr>")
Clock=Clock+#0:30#
End If
End If
TBL.MoveNext
Loop
%>
</table>
</BODY>
</HTML>
<% TBL.Close
Set TBL=Nothing
Set DB=Nothing
%>
I am attempting to write a page which creates an HTML table 1 column wide and with enough rows in to cover the time period 8am to 6pm divided into half hour slots. I also have a database that has 4 main columns - StartTime, EndTime, RoomID and Date. It contains information about whether a boardroom has been booked for use. The idea is the table is being drawn if the room is in use at that point the background is yellow and if it's not the background is white. If a boardroom is in use for say 2 hours I would want all 4 rows to be yellow - not just the first and last ones.
I am running into two problems - 1 how to handle a case where it looks up something in the database and there's nothing there. Either it crashes out or it doesn't complete the table. Even if the room isn't being used all day I would still want to show the table. The second is more of a semantics problem - when I try to compare the time in the row of the table with the time in the recordset it doesn't seem to work properly. Maybe it's because I have inadvertently converted them to strings rather than time values...I'm not sure!
Anyway this is what I've got so far - would be very grateful for any assistance! Thanks:
<%
Set DB = Server.CreateObject("ADODB.Connection")
Set TBL = Server.CreateObject("ADODB.RecordSet")
DB.Mode = adModeReadWrite
DB.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("../directory/userdb.mdb"))
TBL.Open "SELECT StartTime, EndTime FROM Bookings WHERE Date=#" & Date & "# AND RoomID=" & Request.QueryString("Room") & " ORDER BY StartTime ASC", DB
%>
<HTML>
<BODY>
<font face="verdana" size="3">
<b>Schedule for Today - Boardroom <% = Request.QueryString("Room")+1 %></b><br><br>
<table width="100%" cellspacing="5" cellpadding="5" border="1">
<%
Clock=#08:00#
Do While Clock < #18:30#
If Not TBL.EOF Then
StartTime = "#" & TBL("StartTime") & "#"
EndTime = "#" & TBL("EndTime") & "#"
If Clock >= StartTime AND Clock < EndTime Then
Do While Clock < EndTime
Response.Write("<tr>")
Response.Write("<td")
Response.Write(" bgcolor='FFFFCC'>")
Response.Write("</td>")
Response.Write(Clock)
Response.Write("</tr>")
Clock = Clock + #0:30#
Loop
Else
Response.Write("<tr><td>")
Response.Write(Clock)
Response.Write("</td></tr>")
Clock=Clock+#0:30#
End If
End If
TBL.MoveNext
Loop
%>
</table>
</BODY>
</HTML>
<% TBL.Close
Set TBL=Nothing
Set DB=Nothing
%>