and thankyou for reading my question. Using a for loop in PHP, I was looking to accomplish an echo for a list of times (offset by 5 minutes) in between an open and closing time of a business. That challenge was not a problem to program, my code outputs a huge list of <option>
tags with time values inside each of the (offset by 5 minutes) succesfully:
I.E:
<option value="2013-06-06 08:00:00">8:00 am</option>
<option value="2013-06-06 08:05:00">8:05 am</option>
<option value="2013-06-06 08:10:00">8:10 am</option>
.....etc.
However, I have a MYSQL table setup that has a column inside of each row (setup in DATETIME format), that is the time of tee off....as many may know you can't have more than one person booked to tee off at once so I am trying to make it where, if that time (inside that for loop) is equal to any of the (booked) times fetched from database, that value will not echo in that list.
Below is my code, (the for loop at least) this is what is outputing the <option>
tags:
(Also as you can see I attempted to make an IF statement there that says if the $time equals $tee_times_from_mysql don't echo that <option>
...then continue to check the next, and so on.) This worked, however, when the $tee_times_from_mysql was SELECT-ed from my MYSQL database, it only took the most recently booked tee time (only one) and excluded that....the rest got ignored (or simply were never fetched, not sure)....so it doesn't work if there is more than one booked tee time (which there is obviously going to be more than that)....my question is how do I exclude a time if they equal any of times in the database.
for ($i=$startHour; $i <= $endHour; $i++)
{
for ($j = 0; $j <= 55; $j+=5)
{
$time_pre = $i.":".str_pad($j, 2, '0', STR_PAD_LEFT);
$time = ''.$time_pre .' '.$day.'';
/////////////////////////////
$time_formated_for_cosmetic = date("g:i a", strtotime("$time"));
$time_formated_for_mysql = date("Y-m-d H:i:s", strtotime("$time"));
if ($time == $tee_times_from_mysql){
$time = '';
}
else{
$time = '<option value="' . $time_formated_for_mysql . '">'.$time_formated_for_cosmetic .'</option>';
}
echo $time;
}
}
THIS IS MY MYSQL FETCH ALSO:
$tee_times_from_mysql = "";
$sql = "SELECT * FROM tee_times";
$query = mysqli_query($db_conx, $sql);
while($row = mysqli_fetch_assoc($query)){
$tee_times_from_mysql = $row["date_time"];
$tee_times_from_mysql = date("G:i n/j/y", strtotime("$tee_times_from_mysql"));
}