Hi
I’m pulling my hair out having spent around 10 hours trying to fix this if it is fixable at all.
My script is a calender booking system which shows available slots through the day in the duration of time ie 20 mins a slot. It uses an hour counter and minute counter and checks with the db to see if the time is free or booked. This works all fine until you change the duration so the minute counter goes up in 20 min intervals or 15 minutes etc.
Lets say we have a 15 minute slot running, ie 0, 15, 30, 45, 60, 15
I have a booking 9 to 9:50 the next available slot would be 9:50 so I need to make the minute counter change to this time in minutes and not keeping going up in 15 minute increments, I have added this in but it all goes wrong. Very difficult to explain, minutes part of the code is below with error.
Full Code is below that.
Any help would be great
Steve
for($m=$mins; $m<60; $m++)
{
//echo(“Minutes:$m<br>”);
$minutes = $m;
$timeStamp = “$dateNum $dateMonth $dateYear $h:$minutes GMT”;
$unix = strtotime($timeStamp);
$unixSlotTimeLength = $unix+(60*$duration)-60;
$bookedStatus="";
$availableStatus = "";
//check there is a booking
$query = "SELECT slotStatus FROM tblTimeSlots WHERE slotTime>='$unix' AND slotTime<='$unixSlotTimeLength' AND timeSlotID=1 ORDER BY id ASC";
//echo ("$query<br>");
$result = mysql_query($query,$db);
while($row = mysql_fetch_array($result))
{
$status = $row[slotStatus];
if($status=="BOOKED")
{
$bookedStatus ="BOOKED";
}
elseif($status=="AVAILABLE")
{
$availableStatus = "AVAILABLE";
}
else
{
$availableStatus = "NOT AVAILABLE";
}
}
if($availableStatus=="AVAILABLE" && $bookedStatus!="BOOKED")
{
$timeStamp = "$dateNum $dateMonth $dateYear $h:$minutes GMT";
if($minutes==0)
{
$minutes="00";
}
$showTime = gmdate("g:i",$unix);
echo("<a href='/test5c.php?createAppointment=Y&slotFromTime=$unix&slotToTime=$unixSlotTimeLength&clientID=$clientID&staffID=$staffID&timeSlotID=$timeSlotID'>$showTime</a><br>");
$m+=$duration;
if($m>59)
{
$minsLeft = $m - 60;
// add to array
$minsLeftArray[$counter] = $minsLeft;
$minsLeft="Y";
$slotStatus="";
}
}
elseif($bookedStatus=="BOOKED")
{
$unixSlotTimeLength = gmdate("i",$unixSlotTimeLength+60);
if($unixSlotTimeLength=="00")
{
$unixSlotTimeLength = 59;
}
echo("BOOKED<br>");
//$m+=$duration; //
// ************** ERROR PART **************
$m=$unixSlotTimeLength;
// ***************************************
//echo("End Slot Time Min : $unixSlotTimeLength<br>");
//$m=$unixSlotTimeLength;;
//echo("minutes After: $m<br>");
if($m>59)
{
$minsLeft = $m - 60;
$minsLeftArray[$counter] = $minsLeft;
$minsLeft="Y";
$slotStatus="";
}
}
else
{
echo("NOT AVAILABLE<br>");
$m+=$duration;
if($m>59)
{
$minsLeft = $m - 60;
$minsLeftArray[$counter] = $minsLeft;
$minsLeft="Y";
$slotStatus="";
}
}
// end of minute loop
$m=$m-1;
}// end of minute loop
FULL CODE :
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1” />
<title>Untitled Document</title>
</head>
<body>
<p>
<?
if($createAppointment!=“”)
{
$query = “UPDATE tblTimeSlots SET slotStatus=‘BOOKED’ WHERE slotTime>=‘$slotFromTime’ AND slotTime<=$slotToTime AND clientID=‘$clientID’ AND staffID=‘$staffID’”;
echo (“$query<br>”);
mysql_query($query,$db);
}
//$todayStartDate = time();
//variables
$clientID = 123;
$staffID = 456;
$query = “SELECT timeSlotID, slotStartTime, slotFinishTime FROM tblTimeSlotDetails WHERE clientID=‘$clientID’ AND staffID=‘$staffID’”;
echo $query;
$result = mysql_query($query,$db);
$row = mysql_fetch_array($result);
$timeSlotID = $row[timeSlotID];
$hourStart = $row[slotStartTime];
$hourFinish = $row[slotFinishTime];
//$hourStart = 9;
//$hourFinish = 17;
if($duration==“”)
{
$duration = 25;
}
$slotDuration = $duration;
$slotsPerHour = 60/$slotDuration;
echo(“Duration : $duration”);
if($nextWeek!=“”)
{
$date = strtotime(“$day-$month-$year GMT”);
$todayNow = $date + 604800;
echo $todayNow;
}
else
{
$todayNow = time();
}
$dateDay = date(‘D’, $todayNow) ;
$dateNum = date(‘j’, $todayNow) ;
$dateYear = date(‘Y’, $todayNow);
$dateMonth = date(‘n’, $todayNow);
?>
</p>
<p><a href=“/test5c.php?duration=25”>Gel</a> = 25 min<br />
<a href=“/test5c.php?duration=15”>Soak</a> = 15min<br />
<a href=“/test5c.php?duration=45”>Nail</a> = 45min
<br /><a href=“/test5c.php?duration=10”>Scrub</a> = 10 min <br />
</p>
<p> </p>
<?
echo(“<a href=‘/test5b.php?nextWeek=Y&day=$dateNum&month=$dateMonth&year=$dateYear’>Next Week</a>”);?>
<table width=“900” border=“1” cellpadding=“0” cellspacing=“0”>
<tr><td>time</td>
<?
// create top row of days for current timr
for($i =0; $i<7; $i++)
{
$time = 86400 * $i;
$newTime = $todayNow + $time;
$dateDay = date('D', $newTime) ;
$dateNum = date('j', $newTime) ;
echo("<td>$dateDay $dateNum</td>");
}
?>
</tr>
<?
//$todayNow = time();
// hourly time slot rows + needs 7 vertical columns for time
for($h=$hourStart; $h<=$hourFinish; $h++)
{
echo(“<tr>”);
// columns 7 for each day
for($c = 0; $c <7; $c++)
{
$counter++;
if($h==$hourStart)
{
$minsLeft="";
}
$time = 86400 * $c;
$newTime = $todayNow + $time;
$dateNum = date('j', $newTime);
$dateYear = date('Y', $newTime);
$dateMonth = date('M', $newTime);
// build up date and time from $h
$timeStamp = "$dateNum $dateMonth $dateYear $h:00 GMT";
$unix = strtotime($timeStamp);
// left hand column
if($c==0)
{
// display hour column on left
if($h>12 && $h<=23)
{
$columnTime = $h - 12;
$columnTime = $columnTime ."pm";
}
else
{
$columnTime = $h."am";
}
echo("<td>$columnTime</td>");
}
// end of column on left
echo("<td>");
// START OF BOOKING TESTHOUR INTERGRATION //
if($minsLeft=="Y")
{
// get value from array
$mins = $minsLeftArray[$counter-7];
$minsLeft ="";
}
else
{
$mins=0;
}
for($m=$mins; $m<60; $m++)
{
//echo("Minutes:$m<br>");
$minutes = $m;
$timeStamp = "$dateNum $dateMonth $dateYear $h:$minutes GMT";
$unix = strtotime($timeStamp);
$unixSlotTimeLength = $unix+(60*$duration)-60;
$bookedStatus="";
$availableStatus = "";
//check there is no booking
$query = "SELECT slotStatus FROM tblTimeSlots WHERE slotTime>='$unix' AND slotTime<='$unixSlotTimeLength' AND timeSlotID=1 ORDER BY id ASC";
//echo ("$query<br>");
$result = mysql_query($query,$db);
while($row = mysql_fetch_array($result))
{
$status = $row[slotStatus];
if($status=="BOOKED")
{
$bookedStatus ="BOOKED";
}
elseif($status=="AVAILABLE")
{
$availableStatus = "AVAILABLE";
}
else
{
$availableStatus = "NOT AVAILABLE";
}
}
if($availableStatus=="AVAILABLE" && $bookedStatus!="BOOKED")
{
$timeStamp = "$dateNum $dateMonth $dateYear $h:$minutes GMT";
if($minutes==0)
{
$minutes="00";
}
$showTime = gmdate("g:i",$unix);
echo("<a href='/test5c.php?createAppointment=Y&slotFromTime=$unix&slotToTime=$unixSlotTimeLength&clientID=$clientID&staffID=$staffID&timeSlotID=$timeSlotID'>$showTime</a><br>");
$m+=$duration;
if($m>59)
{
$minsLeft = $m - 60;
// add to array
$minsLeftArray[$counter] = $minsLeft;
$minsLeft="Y";
$slotStatus="";
}
}
elseif($bookedStatus=="BOOKED")
{
$unixSlotTimeLength = gmdate("i",$unixSlotTimeLength+60);
if($unixSlotTimeLength=="00")
{
$unixSlotTimeLength = 59;
}
echo("BOOKED<br>");
//$m=$unixSlotTimeLength;
$m+=$duration;
//echo("End Slot Time Min : $unixSlotTimeLength<br>");
//$m=$unixSlotTimeLength;;
//echo("minutes After: $m<br>");
if($m>59)
{
$minsLeft = $m - 60;
$minsLeftArray[$counter] = $minsLeft;
$minsLeft="Y";
$slotStatus="";
}
}
else
{
echo("NOT AVAILABLE<br>");
$m+=$duration;
if($m>59)
{
$minsLeft = $m - 60;
$minsLeftArray[$counter] = $minsLeft;
$minsLeft="Y";
$slotStatus="";
}
}
// end of minute loop
$m=$m-1;
}// end of minute loop
echo("</td>");
} // end of column loop
echo("</tr>");
} // end of hour loop
?>
</table>
<p> </p>
<p> </p>
<table width=“400” border=“1” cellpadding=“0” cellspacing=“0”>
<tr>
<td width=“102” rowspan=“2”>1</td>
<td width=“69”>2</td>
<td width=“221” rowspan=“2”>4</td>
</tr>
<tr>
<td>3</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
</table>
<p> </p>