Forum Moderators: coopster
I'm in the process of creating an online booking system, and am trying to get the user to change the time of a appointment.
Now I'm not quite sure of how to do this, I have made a start on the initial code. Just want to get this bit working, then I know what to do next.
Firstly I get all the times booked on a given day, and place them into an array. Then I get all booking times using a for loop from 10:00 to 17:00. Then I imagine you have to compare the 2 arrays and find out what times you can book.
An example would that these are the time booked up:-
10:00
10:15
10:30
10:45
11:00
Then the times available would be 11:15,11:30 and so forth till 17:00.
Any ideas guys?
Code:
$result=mysql_query("select bktimes from booking_times,streamline_shows,cmsengineers
where booking_times.shid=streamline_shows.shid
and showname='$showname'
and bkdate='$bkdate'
and booking_times.engineernum=cmsengineers.engineernum
and firstname='$firstname'
and surname='$surname'
order by bktimes");
while (list($DBbktimes)=mysql_fetch_row($result))
$times[]=$DBbktimes;
$cnt=0;
$start=mktime(10,0,0,date('m'),date('d'),date('Y'));
for($i=$start;$i<=$start+25200;$i+=900)
{
$time=date("H:i",$i)."<BR>";
$timeav[]=$time;
}
Many Thanks
I did try using array_diff but that didn't work as I think it should, this is the output I got.
$result=mysql_query("select bktimes from booking_times,streamline_shows,cmsengineers
where booking_times.shid=streamline_shows.shid
and showname='$showname'
and bkdate='$bkdate'
and booking_times.engineernum=cmsengineers.engineernum
and firstname='$firstname'
and surname='$surname'
order by bktimes");
while (list($DBbktimes)=mysql_fetch_row($result))
$times[]=$DBbktimes;
print_r($times);
$start=mktime(10,0,0,date('m'),date('d'),date('Y'));
for($i=$start;$i<=$start+25200;$i+=900)
{
$time=date("H:i",$i)."<BR>";
$timeav[]=$time;
}
print_r($timeav);
echo "<pre>";
print_r(array_diff($times, $timeav));
echo "</pre>";
Array ( [0] => 10:00 [1] => 10:15 [2] => 10:30 [3] => 10:45 [4] => 11:00 )
Array ( [0] => 10:00
[1] => 10:15
[2] => 10:30
[3] => 10:45
[4] => 11:00
[5] => 11:15
[6] => 11:30
[7] => 11:45
[8] => 12:00
[9] => 12:15
[10] => 12:30
[11] => 12:45
[12] => 13:00
[13] => 13:15
[14] => 13:30
[15] => 13:45
[16] => 14:00
[17] => 14:15
[18] => 14:30
[19] => 14:45
[20] => 15:00
[21] => 15:15
[22] => 15:30
[23] => 15:45
[24] => 16:00
[25] => 16:15
[26] => 16:30
[27] => 16:45
[28] => 17:00
)
Array
(
[0] => 10:00
[1] => 10:15
[2] => 10:30
[3] => 10:45
[4] => 11:00
)
As you can see the times available should be from 11:15 on wards, any ideas?
So in essence it should print like this...
[5] => 11:15
[6] => 11:30
[7] => 11:45
[8] => 12:00
[9] => 12:15
[10] => 12:30
[11] => 12:45
[12] => 13:00
[13] => 13:15
[14] => 13:30
[15] => 13:45
[16] => 14:00
[17] => 14:15
[18] => 14:30
[19] => 14:45
[20] => 15:00
[21] => 15:15
[22] => 15:30
[23] => 15:45
[24] => 16:00
[25] => 16:15
[26] => 16:30
[27] => 16:45
[28] => 17:00
Cheers.
Also, you have the array order reversed in the array_diff() [php.net] syntax.
$start = mktime(10,0,0,date('m'),date('d'),date('Y'));
for ($i=$start;$i<=$start+25200;$i+=900) {
$time = date("H:i",$i); // removed the <BR> here!
$timeav[] = $time;
}
echo '<pre>';
print_r(array_diff($timeav, $times));
echo '</pre>';