I have a php application for reservations that has a stats page that queries the database and produces a graph of reservations by day for the given month. The graph works just fine, but the graph labels for the day of the week are wrong or off. Meaning that if I have data for three days in the month it graphs it, the interval between days is correct but the label is wrong. So in my tests I have reservations on Monday Thursday Friday and the data came back Sun/Mon/Thur
All the other reports on the page work fine, so I will attempt to provide the code I have researched or traced that relates to the graph I am having problems with. I hope, I am not a php coder and my hope is to get some help with the one little glitch rather than rebuild an entire stats package for the site. Original developer is gone so I can't get help their either.
function get_first_day($day_number=1, $month=false, $year=false)
{
$month = ($month === false) ? strftime("%m"): $month;
$year = ($year === false) ? strftime("%Y"): $year;
$first_day = 1 + ((7+$day_number - strftime("%w", mktime(0,0,0,$month, 1, $year)))%7);
return mktime(0,0,0,$month, $first_day, $year);
}
I have found this out there and looks correct from what I can tell to get first day of the month adjustment. Note that changing the $day_number= did not have any effect.
My next assumption is that this array and sql query get the data. The SQL query, just calls the sum of reservations AS paxsum from the table. Based on certain criteria and current session variables.
// Bar Plot Guest by weekday/month
$data_wk = array();
$label_wk = array();
$statistic = querySQL('statistic_weekday');
foreach ($statistic as $key => $value) {
foreach($value as $paxsum){
$label_wk[] = $key;
$data_wk[] = $paxsum;
}
}
I then found that this is what produces the graph and labels.
<table id="graph_weekday" class="data" style="display:none" cellpadding="0" cellspacing="0" width="100%">
<caption><?php echo _occupancy_per_week." / "._days;?></caption>
<thead>
<tr>
<td class="no_input"> </td>
<?php
foreach ($label_wk as $value) {
echo "<th>".strftime("%A", get_first_day($value, $_SESSION['statistic_month'], $_SESSION['selectedDate_year']))."</th>";
}
?>
</tr>
</thead>
<tbody>
<tr>
<th><?php echo _days;?></th>
<?php
foreach ($data_wk as $value) {
echo "<td>".$value."</td>";
}
?>
</tr>
</tbody>
</table>
}
?>