I have developed an on-line diary of sorts. It allows the user to book, among other things, a place a time and a date. I have a select pull down with times starting at 10:30am and ending at 5:00pm at 15 minute intervals. I believe this is around 28 time slots in total. There is another select box with 8 places to select from. All of this information is put into MySql. I have even written code to only allow 6 bookings for each location at a specified time. What I want to do now is run a query that tells me how many time slots are avalable for each time and place, and list it on the page.
The query would be something like
Select count(*) from settlements where time ='10:30am' and location = NAB
Then subract that from 6 and so on.....
My problem is that I have to do this 28 times for each place.
I am familiar with for loops and/or arrays, but not sure which way to go with this.
Thanks for any input.
Jim Durand
Steer me in the right direction
Moderator: General Moderators
Ok, I don't know if this is the best solution but here is where I'm heading. I haven't organised printing into tables yet as this is still being developed.
Eventually I will get the date from the posted form.
I have used two arrays and nested FOR statements. I am only showing two locations here.
I originally used some of this code to populate the select satement in the form. I have used the same code to populate the time slot array. Anyway here it is so far:
Eventually I will get the date from the posted form.
I have used two arrays and nested FOR statements. I am only showing two locations here.
I originally used some of this code to populate the select satement in the form. I have used the same code to populate the time slot array. Anyway here it is so far:
Code: Select all
$time_table = Array(); //Array for time slots
$place_array = Array(0,"NAB","BOQ");//Array for locations
$inc = 30; //Prepare variables for time slot code
$hour_count = 3;
$hour_num = 1;
$hour = 10;
for ($pa=1; $pa<3; $pa++) { //for each location
print $place_array[$pa] ; //Show location
//Same code used to populate select box
for ($i=1; $i<28; $i++) { //Sets time slots 10:30am-5:00pm
if ($hour_count == 1) {
if ($hour < 12 and $hour > 7) {
$time_table[$i] = $hour . ":" . "00" . "am";
} else {
$time_table[$i] = $hour . ":" . "00" . "pm";
}
$hour_count++;
} else {
if ($hour < 12 and $hour > 7) {
$time_table[$i] = $hour . ":" . $inc . "am";
} else {
$time_table[$i] = $hour . ":" . $inc . "pm";
}
$inc = $inc + 15 ;
$hour_count++;
if ($hour_count == 5) {
$inc = 15;
$hour_count = 1;
$hour++;
}
}
if ($hour == 13) { //Take care of 24 hour clock
$hour = 1 ;
}
//Check for number of bookings for timeslot
$sql = "SELECT COUNT(*) FROM settlements WHERE starttime = '$time_table[$i]' and location = '$place_array[$pa]' ";
$result = mysql_query($sql);
$numberused = mysql_result($result,0,0);
print $time_table[$i] . " Has " . (6 - $numberused) . " Slots Left" ;
}//end first FOR
}//end nested FOR
?>