I'm trying to pull data from a database to show reservations in a table that looks like a weekly calendar. The reserved hours should take the "reserve" class. For some reason, it looks like my foreach loops aren't executing. The way the code is written now, the table should just read "test" for each data entry.
$schedule = mysql_query ("SELECT * FROM reservation WHERE location_id = '$reserve' AND year = '$year' AND quarter = '$quarter' AND date_note = 'Quarter' ORDER BY hour_start ASC");
foreach ($time as $hour) {
$endhour = $hour + 30;
foreach ($week as $day) {
while ($sched_table = mysql_fetch_array($schedule)) {
if ($sched_table['day_of_week'] == $day) {
if ($sched_table['hour_start'] == "") {
echo "<td>test</td>";
} elseif ($sched_table['hour_start'] >= $hour && $sched_table['hour_start'] < $endhour) {
echo "<td class='reserve'>test</td>";
} else {
echo "<td>test</td>";
}
}
}
}
}
All of the variables above are defined earlier as such:
$reserve = $_POST['reserve'];
$year = 2013;
$quarter = "Fall";
$week = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$time = array();
for ($x = 800; $x < 2001; $x += 100) {
$y = $x + 30;
array_push($time, $x, $y);
}
Some quick notes--I realize that the haven't been set before the foreach loops. I wanted to make sure the loops were running before I figured out where to start and end each row, so I just put a echo ""; and echo ""; at the beginning and the end of the entire statement. This should have made one long list of "test", but nothing is showing.
The database stores the start times as "0900" instead of "900". Would that explain why the loops aren't executing? And if that's the case, would I have to redefine $time so they exist as strings, or would I be able to work with them as a value.
Thanks for the help.
After the first time through the inner foreach loop
mysql_fetch_array($schedule)
will always return false. If the database doesn't have any schedules for 8:00 Sunday then it will look like none of the loops ran.
Try resetting the result pointer with
mysql_data_seek($schedule, 0)
(mysql_data_seek Documentation)
0 comments:
Post a Comment