I have in PHP:
<?php
$columns = array('mon','thu','wed','tue', 'fri', 'sat', 'sun');
$num_cols = count($columns);
$col = 0;
$datetime = new DateTime("06:00");
echo "<table>"; // border=\"1\" for visible border
// Day header
echo "<tr>";
foreach($columns as $col) {
echo "<td at='$col'>$col</td>";
}
echo "</tr>";
// Times
for($i=0; $i<20; $i++) { // FIXME for more entries or other step width
echo "<tr>";
$datetime->modify('+30 minutes');
for ($j=0; $j<$num_cols; $j++)
echo '<td class="' . $datetime->format('H:i') . '">' . $datetime->format('H:i') . '</td>';
echo "</tr>";
}
echo "</table>";
?>
and in database MySQL:
id | day | hours
1 | mon | 07:00
2 | thu | 08:40
3 | wed | 12:30
4 | thu | 13:00
5 | fri | 05:00
etc
how is the best method for checking this? If date is in database then i would like make TD with red background, for example add class red:
echo "<td at='$col' class='red'>$col</td>";
Check this in each loop FOR is not good idea – this generated to many query for database.
How can i make it?
I can use also jquery and for example JSON if this is possible.
List them all in a keyed array, then when looping through the calendar simply check for these keys.
For example, you’d get the array
array(1 => array('07:00' => true))(day of the week => appointments).You can then check
isset($array[$datetime->format('N')][$datetime->format('H:i')])