I am trying to echo an array of check boxes with clock times in them ([ ] 9:00 , [ ] 10:00 etc). The clock times vary depending on the user's input.
The problem is that the very first clock time in the array doesn't have a check box. I am sure it is something obvious--but at this point I am blind.
Also, I am using what I think is a clunky approach to extracting the values from the array ( the foreach routine). It works...but I am open to a better way if there is one.
It's short program. I have included the entire module.
Any help would be appreciated.
<?php
// This program lets the user enter the starting time of a game and how much time is alloted from the start of the first game to the start of the second game. It provides checkboxes for the scheduler to choose what starting times he wants each game to begin.
//This is will be used as an include file
// Drop down menu to output hours and minutes
echo "<form method ='post'>";
function timeSelect($name,$mode,$selected) {
if($mode) {
$mode = 24;
} else {
$mode = 60;
}
echo '<select name="'.$name.'" >';
echo '<option value="-1">--</option>';
for ($i=0;$i<$mode;$i++) {
if($i <=9) {
$i = "0".$i;
}
if($i == $selected) {
echo '<option selected="selected" value="'.$i.'" >'.$i.'</option>';
} else {
echo '<option value="'.$i.'" >'.$i.'</option>';
}
}
echo '</select>';
}
//call the starting hour and minutes
timeSelect("event_start_hour",true,$_POST['event_start_hour']);
timeSelect("event_start_minute",false,$_POST['event_start_minute']);
echo "<br />";
//DURATION
echo "Minutes from Start of first game to start of second game
<input name='duration' type='text' value='$duration' maxlength=4> For example 90 = 90 minutes.<br />";
echo "<input type='submit' value ='submit' name='processTime'>";
echo "</form><br />";
if($_POST['processTime'])
{
$matchStartTime = $_POST['event_start_hour'].":". $_POST['event_start_minute'];
$duration = $_POST['duration'];
echo "Time start is $matchStartTime and duration is $duration<br />";
}
echo "<br />";
// This function process the time, adding a user inputted duration
function addTime($timeString, $duration)
{$event_time = $timeString;
$event_length = $duration;
$timestamp = strtotime("$event_time");
$etime = strtotime("+$event_length minutes", $timestamp);
$next_time = date('h:i:s' , $etime);
return $next_time;
}
echo "<BR>";
print "<form method ='post'";
$cts = 0; //$cts stands for count the slots
while ($cts < 7) //7 is the maximum number of slots that can be processed in a day.
{
print "<input type = 'checkbox'
name='matchStartTime_ud[]'
value='$matchStartTime'>$matchStartTime | ";
$next_time = addTime($matchStartTime,$duration);
$matchStartTime= $next_time;
$cts++;
}
echo "<input type ='submit' name='getTime' value= 'see results'<br />";
echo "</form>";
foreach($_POST['matchStartTime_ud'] as $hm)
{
echo "time is " . $hm[0] . " " . $hm[1] . " " . $hm[2]. " " . $hm[3]. " " . $hm[4] . "<br />";
$timeIs = $hm[0].$hm[1].$hm[2].$hm[3].$hm[4];
print $timeIs ."<br />";
}
?>