PDA

View Full Version : Loop Problem


Balders
10-20-2005, 02:51 PM
Hi there,

I'm working on a booking project, where user can book appointments at let's say hair dressers. When there is no booking at all, it returns all time slots, if there is a booking at 16:00 it returns only one booking for 9:00 and it should return all the others between as well (9:00, 9:30, 10:00 etc). It doesn't loop, and it should but where am I wrong? HELP PLEASE!

<%



Set rsBookings = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM tblBookings WHERE staffID = " & Request.Form("staffID") & " AND bookingDate = #" & bookingDate & "# ORDER BY bookingTimeFrom"



rsBookings.open strSQL, conn

if not rsBookings.eof then

strBooking = "<ul>"

x = openTime

Do while not rsBookings.eof

availSlot = DateDiff("n", x, rsBookings("bookingTimeFrom"))



if availSlot >= hours then

strBooking = strBooking & "<li><input type=""radio"" name=""bookingFrom"" value=""" & x & """ />" & FormatDateTime(x,vbShortTime) & "</li>" &vbcrlf

end if

x = rsBookings("bookingTimeTo")

rsBookings.movenext

loop

availSlot = DateDiff("n", x, closeTime)

if availSlot >= hours then


strBooking = strBooking & "<li><input type=""radio"" name=""bookingFrom"" value=""" & x & """ />" & FormatDateTime(x,vbShortTime) & "</li>" &vbcrlf

end if

x = DateAdd("n", 30, x)

Do While DateDiff("n", x, DateAdd("n",-hours,closeTime)) > 0

strBooking = strBooking & "<li><input type=""radio"" name=""bookingFrom"" value=""" & x & """ />" & FormatDateTime(x,vbShortTime) & "</li>" &vbcrlf

x = DateAdd("n", 30, x)

Loop

strBooking = strBooking & "</ul>"

else

strBooking = "<ul>"&vbcrlf

x = openTime

Do While DateDiff("n", x, DateAdd("n",-hours,closeTime)) > 0

strBooking = strBooking & "<li><input type=""radio"" name=""bookingFrom"" value=""" & x & """ />" & FormatDateTime(x,vbShortTime) & "</li>" &vbcrlf

x = DateAdd("n", 30, x)

Loop



strBooking = strBooking & "</ul>"

end if

response.write strBooking

%>

neocool00
10-24-2005, 09:03 PM
What is the value of hours and opentime?

Bullschmidt
10-25-2005, 11:53 PM
In general I'd suggest the concept right joining with a table of all allowable times. That's what I've done in creating calendars...