PHP Calendar Issues - php

I have the following code that I created to generate a Calendar, but it has some issues:
//Labels
$dayLabels = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
$monthLables = array("January","February","March","April","May","June","July","August","September","October","November","December");
//max values
$maxDays = 7;
$maxMonths = 12;
//stats
$forceMonth = $_GET['m'];
$forceYear = $_GET['y'];
$todayDate = date("d-m-Y");
$todayDate = date("d-m-Y", strtotime($todayDate));
$explodeToday = explode("-", $todayDate);
$currentDay = $explodeToday[0];
if(isset($forceMonth)) {
$currentMonth = $forceMonth;
} else {
$currentMonth = $explodeToday[1];
};
if(isset($forceYear)) {
$currentYear = $forceYear;
} else {
$currentYear = $explodeToday[2];
};
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $currentYear);
//database values
$startDate = array("01-06-2015","25-06-2015");
$endDate = array("05-06-2015","05-07-2015");
$bookedUser = array("Dexter","James");
//counters
$daysIntoMonth = 0;
$dayCounter = 0;
//debug
echo '<p>Current Month: ' .$monthLables[$currentMonth-1]. ' / ' .$currentMonth. '</p>';
echo '<p>Current Year: ' .$currentYear. '</p>';
//start of Calendar
echo '<table>';
//print days of week
echo '<tr>';
foreach($dayLabels as $day) {
echo '<td style="border-bottom:dashed 1px #DDD;">' .$day. '</td>';
};
echo '</tr>';
while($daysIntoMonth < $daysInMonth) {
//days into month
$daysIntoMonth++;
$temp_inMonth = sprintf("%02d", $daysIntoMonth);
$daysIntoMonth = $temp_inMonth;
//days into week
$dayCounter++;
$temp_dayCounter = sprintf("%02d", $dayCounter);
$dayCounter = $temp_dayCounter;
//current calendar date
$calDate = date('d-m-Y', strtotime($daysIntoMonth. '-' .$currentMonth. '-' .$currentYear));
$timeCal = strtotime($calDate);
if($dayCounter == 1) {
echo '<tr>';
};
if($startKey = array_search($calDate, $startDate) !== FALSE) {
$booked = true;
};
if($endKey = array_search($calDate, $endDate) !== FALSE) {
$booked = false;
};
if($booked == true) {
echo '<td style="background-color:red;">' .$calDate. ' / ' .$daysIntoMonth. ' ' .$dayCounter. '</td>';
} else if($booked == true && array_search($calDate, $startDate) !== FALSE) {
echo '<td style="background-color:red;">' .$calDate. ' / ' .$daysIntoMonth. ' ' .$dayCounter. '</td>';
} else if($booked == false && array_search($calDate, $endDate) !== FALSE) {
echo '<td style="background-color:red;">' .$calDate. ' / ' .$daysIntoMonth. ' ' .$dayCounter. '</td>';
} else {
echo '<td>' .$calDate. ' / ' .$daysIntoMonth. ' ' .$dayCounter. '</td>';
}
if($dayCounter == $maxDays) {
echo '</tr>';
$dayCounter = 0;
};
};
//table is kill
echo '</table>';
The issues I have noticed:
Unable to put a $bookedUser for respective $startDate,$endDate.
When a booking laps over to another month, it skips all the dates until the $endDate.
All Months start on Monday, how would I go about making them start of correct days of the week.
Possible code examples to help me solve my issues would be great, thanks in advance.
Edit:
I have solved problem 3 by using the following code:
$firstDayofMonth = strtotime("01-$currentMonth-$currentYear");
$firstDayofMonth = date("D", $firstDayofMonth);
$firstDayofMonth = array_search($firstDayofMonth, $dayMiniLabels);
$firstDayofMonth = $firstDayofMonth + 1;
$startMonth = 0;
if($firstDayofMonth != 7) {
while($startMonth < $firstDayofMonth) {
echo '<td></td>';
$startMonth++;
$dayCounter++;
$temp_dayCounter = sprintf("%02d", $dayCounter);
$dayCounter = $temp_dayCounter;
};
};

For the days and months (problem 3), I would do this:
$todaysNumber = date('w');
$currentDayInText = $dayLabels[$todaysNumber];
And the same for the monhts.
Mostly, in my MySQL-tables, dates are placed like 2015-06-05 and not in European time notation. Maybe that could solve problem 1?

Related

How to display days in a grid by weeks in php?

I am trying to display the days of a month in a grid-like or table like form. I was considering using Bulma or bootstrap to handle the grid/tables. The grid is based on 5 rows and 7 columns. I can't figure out how to go about implementing the correct days of the week. Each week should be grouped by a div with dates inside the div. This is what I have so far:
<?php
$row = '';
$startDate = 12/30/2018;
$numDays = 35;
$datesArr = array();
$weekCounter = 1;
for ($i = 0; $i <= numDays; i++) {
$row .= '<div>';
$date = date('m/j/Y', strtotime("$startDate +$i days"));
$datesArr[] = $date;
if ($i % 8 == 0) {
$row .= '<p>Week ' . $weekCounter++ . '</p>';
} else {
$row .= '<p>'.$date . ' - ' . date('l'), strtotime($date)). '</p>';
}
$row .= '</div>';
}
echo $row;
?>
This is my current output:
Week 1
12/31/2018-Monday
01/1/2019-Tuesday
01/2/2019-Wednesday
01/3/2019-Thursday
01/4/2019-Friday
01/5/2019-Saturday
01/6/2019-Sunday
Week 2
01/8/2019-Tuesday
01/9/2019-Wednesday
01/10/2019-Thursday
01/11/2019-Friday
01/12/2019-Saturday
01/13/2019-Sunday
01/14/2019-Monday
Week 3
01/16/2019-Wednesday
01/17/2019-Thursday
01/18/2019-Friday
01/19/2019-Saturday
01/20/2019-Sunday
01/21/2019-Monday
01/22/2019-Tuesday
Week 4
01/24/2019-Thursday
01/25/2019-Friday
01/26/2019-Saturday
01/27/2019-Sunday
01/28/2019-Monday
01/29/2019-Tuesday
01/30/2019-Wednesday
Week 5
02/1/2019-Friday
02/2/2019-Saturday
02/3/2019-Sunday
<?php
$row = '';
$startDate = '12/30/2018';
$numDays = 35;
$datesArr = array();
$weekCounter = 1;
for ($i = 0; $i <= $numDays; $i++) {
$date = date('m/j/Y', strtotime("$startDate +$i days"));
$datesArr[] = $date;
// New div at start of week
if (date("l", strtotime($date)) == "Sunday") {
$row .= "<div style=\"float: left; margin: 10px;\">";
$row .= '<p>Week ' . $weekCounter++ . '</p>';
}
$row .= '<p>'. $date . ' - ' . date("l", strtotime($date)) . '</p>';
// close div at end of week
if (date("l", strtotime($date)) == "Saturday") {
$row .= "</div>";
}
}
echo $row;
?>
You can also consider using jQuery UI Datepicker. You can use AJAX to get a start date and number of days. Then draw the calendar.
$(function() {
function getDateInfo() {
$.getJSON("dateInfo.php", function(data){
drawCal(data.startDate, data.numDays, $(".calendar"));
})
}
function drawCal(sd, nd, tObj) {
var format = "mm/dd/yy";
var min = $.datepicker.parseDate(format, sd);
var max = new Date();
max.setDate(min.getDay() + nd);
console.log(sd, max);
tObj.html("");
tObj.datepicker({
dateFormat: format,
minDate: min,
maxDate: max,
numberOfMonths: [3, 1]
});
}
drawCal("12/31/2018", 35, $(".calendar"));
});
.ui-datepicker-group {
width: 100%;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="calendar"></div>

How to add an element to past days and upcoming days (weekdays only)

i want to change the color to gray from the past weekdays
and to upcoming days change color to blue
my code is:
$week .= str_repeat('<td></td>', $str);
for ( $day = 1; $day <= $day_count; $day++, $str++)
{
$date = $ym . '-' . $day;
if ($today == $date)
{
$week .= '<td class="today">' . $day;
}
else
{
$week .= '<td>'.$day;
}
$week .= '</td>';
// End of the week OR End of the month
if ($str % 7 == 6 || $day == $day_count) {
if ($day == $day_count) {
// Add empty cell
$week .= str_repeat('<td></td>', 6 - ($str % 7));
}
$weeks[] = '<tr>' . $week . '</tr>';
// Prepare for new week
$week = '';
}
}
Here Is My Calendar
Try this:
$previous_days = true;
$week .= str_repeat('<td></td>', $str);
for ( $day = 1; $day <= $day_count; $day++, $str++)
{
$date = $ym . '-' . $day;
if ($today == $date) {
$week .= '<td class="today">' . $day;
$previous_days = false;
}else if($previous_days){
$week .= '<td class="previous-day">'.$day;
}else{
$week .= '<td class="upcoming-day">'.$day;
}
$week .= '</td>';
// End of the week OR End of the month
if ($str % 7 == 6 || $day == $day_count) {
if ($day == $day_count) {
// Add empty cell
$week .= str_repeat('<td></td>', 6 - ($str % 7));
}
$weeks[] = '<tr>' . $week . '</tr>';
// Prepare for new week
$week = '';
}
}

Echo date interval in a PHP calendar

I am creating a calendar and I am in a dire need of a solution. There are records of information in the database and the code reads these records. Two columns hold a date from and a date to. I have to output these dates that appear in the database in different colors. I have tried many times. And the problem is that the code outputs either the last record that it can fetch in the database or all the date periods however these periods get duplicated based on how many rows are there in the database.Here is the output I get
<div id="calender_section_top">
<ul>
<li>Mon</li>
<li>Tue</li>
<li>Wed</li>
<li>Thu</li>
<li>Fri</li>
<li>Sat</li>
<li>Sun</li>
</ul>
</div>
<div id="calender_section_bot">
<ul>
<?php
$dateYear = ($year != '') ? $year : date("Y");
$dateMonth = ($month != '') ? $month : date("m");
$date = $dateYear . '-' . $dateMonth . '-01';
$currentMonthFirstDay = date("N", strtotime($date));
$totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN, $dateMonth, $dateYear);
$totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7) ? ($totalDaysOfMonth) : ($totalDaysOfMonth + $currentMonthFirstDay);
$boxDisplay = ($totalDaysOfMonthDisplay <= 35) ? 35 : 42;
$dayCount = 1;
for ($cb = 1; $cb <= $boxDisplay; $cb++) {
if (($cb >= $currentMonthFirstDay || $currentMonthFirstDay == 7) && $cb <= ($totalDaysOfMonthDisplay - 1)) {
$duh = array();
array_push($duh, $dayCount);
// Current date
$currentDate = $dateYear . '-' . $dateMonth . '-' . $dayCount;
$currentDate = strtotime($currentDate);
$eventNum = 0;
$sql = ("SELECT * FROM booking_2 GROUP BY date_from ORDER BY COUNT(book2_id) DESC");
$result = $this->connect()->query($sql);
$eventNum = $result->num_rows;
if ($eventNum > 0) {
while ($row = $result->fetch_assoc()) {
$date_from = $row['date_from'];
$date_to = $row['date_to'];
$time_from = strtotime($date_from);
$time_fromm = idate('d', $time_from);
$time_to = strtotime($date_to);
$time_too = idate('d', $time_to);
if ($currentDate >= $time_from && $currentDate <= $time_to) {
for ($i = $time_from; $i <= $time_to; $i++) {
$cope = array();
array_push($cope, $dayCount);
}
echo '<li id="' . $row['book2_id'] . '" style="background-color:#FF3232 !important;" date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($cope) . '</span>';
}
}
if (!($currentDate >= $time_from && $currentDate <= $time_to)) {
for ($g = $time_from; $g <= $time_to; $g++) {
$duh = array();
array_push($duh, $dayCount);
}
echo '<li date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($duh) . '</span>';
}
}
else {
echo '<li date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($duh) . '</span>';
}
echo '</li>';
$dayCount++;
?>
<?php
}
else { ?>
<li><span> </span></li>
<?php
}
} ?>
</ul>
</div>
</div>
sorry for TL;DR. But really need help with this. I have tried all the ways I know so if you have a solution can you please be sure that this will work? I believe this is a hard problem to find a solution to.

How can I retrieve data from mysql into my eventcalendar?

I'm trying to retrieve data from my mysql database into a php calendar which I've downloaded from the web. The result from this code is that the page wont stop loading. I know it's somehow related to a loop. I want to highlight the date if there is an event saved with the same date.
db connection//
class Calendar {
public function __construct($year = '', $month = '') {
$date = time();
if (empty($year) OR empty($month)) {
$year = date('Y', $date);
$month = date('m', $date);
$day = date('d', $date);
}
$first_day = mktime(0, 0, 0, $month, 1, $year);
$title = date('F', $first_day);
$day_of_week = date('D', $first_day);
switch ($day_of_week) {
case "Mon": $blank = 0;
break;
case "Tue": $blank = 1;
break;
case "Wed": $blank = 2;
break;
case "Thu": $blank = 3;
break;
case "Fri": $blank = 4;
break;
case "Sat": $blank = 5;
break;
case "Sun": $blank = 6;
break;
}
$days_in_month = cal_days_in_month(0, $month, $year);
echo '<table width="100%" class="table table-striped">';
echo '<tr>';
echo '<th colspan=60>' . $title . ' ' . $year . '</th>';
echo '</tr>';
echo '<tr>';
echo '<td width=62>Mån</td>';
echo '<td width=62>Tis</td>';
echo '<td width=62>Ons</td>';
echo '<td width=62>Tors</td>';
echo '<td width=62>Fre</td>';
echo '<td width=62>Lör</td>';
echo '<td width=62>Sön</td>';
echo '</tr>';
$day_count = 1;
while ($blank > 0) {
echo '<td></td>';
$blank = $blank - 1;
$day_count++;
}
$day_num = 1;
$day_today = date('Y-m-d');
while ($day_num <= $days_in_month) {
$sql = "SELECT id, event_name, event_date FROM events WHERE event_date = '".$day_today."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if(date('d') == $event_date) {
echo "<td> <u>$day_num</u> </td>";
$day_num++;
$day_count++;
}
}
} else {
if(date('d') != $day_num) {
echo "<td> $day_num </td>";
$day_num++;
$day_count++;
}
if(date('d') == $day_num) {
echo "<td> <strong>$day_num</strong> </td>";
$day_num++;
$day_count++;
}
if ($day_count > 7) {
echo '</tr><tr>';
$day_count = 1;
}
}
}
while ($day_count > 1 && $day_count <= 7) {
echo '<td> </td>';
$day_count++;
}
echo '</tr>';
echo '</table>';
}
}
$c = new Calendar($year, $month);
There is no increase of $day_num if the condition in your loop does not apply (and that's the case because $event_date does not exists) and the script will run infinitely.
if (date('d') == $row["event_date"]) // instead of $event_date
On the other hand, this loop and this conditon seems unnecessary to me. If you only want to mark the day, a check on $result->num_rows should be enough.
if ($result->num_rows > 0)
{
echo "<td> <u>$day_num</u> </td>";
$day_num ++;
$day_count ++;
}
Regarding to your database query, you currently request always data for the same day, because $day_today is always the current day. You could try something like this instead:
$check_date = $year ."-". $month ."-". $day_num;
$sql = "SELECT id, event_name, event_date FROM events
WHERE event_date = '" .$check_date . "'";
I hope this helps you further.

How to add row values together in a html table (calendar)?

I have a calendar I made with php using an html table.
Each date has an integer value inserted from the database below the day number.
What I want to do is get the sum of each row (week) of the table and put it in the 8th column. How can I do this?
Any help?
<?php
$conn = mysqli_connect('localhost','username','password','database_name');
?>
<html>
<head>
<title>
Calendar
</title>
<link rel="stylesheet" href="/test/style.css">
<script src="/test/script.js"></script>
</head>
<body>
<?php
//This gets today's date
$date = time() ;
//This puts the day, month, and year in seperate variables
$day = date('d', $date) ;
$month = date('m', $date);
$year = date('Y', $date);
//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;
//This gets us the month name
$title = date('F', $first_day) ;
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day) ;
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year) ;
//Here we start building the table heads
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td>
<td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td><td width=42>Total:</td></tr>";
$day_count = 1;
$row_number = 1;
echo "<tr id='row" . $row_number . "'>";
$row_number++;
//first we take care of those blank days
/////////get beginning of month
if($month-1 != 0) {
$last_month = $month-1;
}
else {
$last_month = 12;
}
if($last_month == '12') {
$year = $year-1;
}
$last_month_first_day = mktime(0,0,0,$last_month, 1, $year);
$last_month_days_in_month = cal_days_in_month(0, $last_month, $year);
$last_month_day_of_week = date('D', $last_mont_days_in_month);
$last_month_days_to_add_to_last_month_end = $blank;
$last_month_end = $last_month_days_in_month-$last_month_days_to_add_to_last_month_end;
//end ^^
while ( $blank > 0) {
echo "<td><span style='color:grey'>" . $last_month_end . "</span></td>";
$last_month_end++;
$blank = $blank-1;
$day_count++;
}
//sets the first day of the month to 1
$day_num = 1;
//count up the days, untill we've done all of them in the month
$week_total_mileage = array();
$x = 0;
while ( $day_num <= $days_in_month ) {
//get total miles from database
$getDay = $year . "-" . $month . "-" . $day_num;
$query = "SELECT * FROM table WHERE date='" . $getDay . "'";
$doQuery = mysqli_query($conn,$query);
while($rows = mysqli_fetch_assoc($doQuery)) {
$total_miles = $rows['total_miles'];
}
$num_rows = mysqli_num_rows($doQuery);
echo "<td id='" . $day_count . $row_number . "' value='" . $total_miles . "'
>
<form method='post' action='/test/day.php'>
<input type='hidden' value='" . $day_num . "' name='day'>
<input type='hidden' value='" . $title . "' name='month'>
<input type='hidden' value='" . $year . "' name='year'>
<input type='button' id='dayNum' value='" . $day_num . "'>
</form>
<span id='totalMiless'>Total miles: ";
if($num_rows == 1) {
echo $total_miles;
}
else {
echo '-';
}
echo "</span>
</td>
<div class='hiddenDay' id='" . $day_num . $title . $year . "' style='display:none'>
<span id='totalMiles'>Total miles: ";
if($num_rows == 1) {
echo $total_miles;
}
else {
echo '0';
}
echo "</span></div>";
$week_total_mileage[$day_num] = $total_miles;
$day_num++;
$day_count++;
if ($day_count > 7) {
$total_total = 0;
while($x < 8) {
$total_total = $total_total + $week_total_mileage[$x];
$x++;
}
while($x < 14 && $x > 8) {
$total_total = $total_total + $week_total_mileage[$x];
}
echo "<td>" . $total_total .
"</td></tr><tr id='row" . $row_number . "'>";
empty($week_total_mileage);
$day_count = 1;
$row_number++;
}
}
//Finaly we finish out the table with some blank details if needed
$end_days = 1;
while ( $day_count >1 && $day_count <=7 ) {
echo "<td><span id='endDays'>" . $end_days . "</span></td>";
$day_count++;
$end_days++;
}
echo "</tr></table>";
?>
</body>
</html>
The above code outputs this:
I just went through your script, put all total miles into an array
and calculate sum with
array_sum
Try this code:
<?php
$conn = mysqli_connect('localhost','username','password','database_name');
?>
<html>
<head>
<title>
Calendar
</title>
<link rel="stylesheet" href="/test/style.css">
<script src="/test/script.js"></script>
</head>
<body>
<?php
//This gets today's date
$date = time() ;
//This puts the day, month, and year in seperate variables
$day = date('d', $date) ;
$month = date('m', $date);
$year = date('Y', $date);
//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;
//This gets us the month name
$title = date('F', $first_day) ;
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day) ;
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year) ;
//Here we start building the table heads
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td>
<td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td><td width=42>Total:</td></tr>";
$day_count = 1;
$row_number = 1;
echo "<tr id='row" . $row_number . "'>";
$row_number++;
//first we take care of those blank days
/////////get beginning of month
if($month-1 != 0) {
$last_month = $month-1;
}
else {
$last_month = 12;
}
if($last_month == '12') {
$year = $year-1;
}
$last_month_first_day = mktime(0,0,0,$last_month, 1, $year);
$last_month_days_in_month = cal_days_in_month(0, $last_month, $year);
$last_month_day_of_week = date('D', $last_mont_days_in_month);
$last_month_days_to_add_to_last_month_end = $blank;
$last_month_end = $last_month_days_in_month-$last_month_days_to_add_to_last_month_end;
//end ^^
while ( $blank > 0) {
echo "<td><span style='color:grey'>" . $last_month_end . "</span></td>";
$last_month_end++;
$blank = $blank-1;
$day_count++;
}
//sets the first day of the month to 1
$day_num = 1;
//count up the days, untill we've done all of them in the month
$week_total_mileage = array();
$weekly_total = array();
$x = 0;
while ( $day_num <= $days_in_month ) {
//get total miles from database
$getDay = $year . "-" . $month . "-" . $day_num;
$query = "SELECT * FROM table WHERE date='" . $getDay . "'";
$doQuery = mysqli_query($conn,$query);
while($rows = mysqli_fetch_assoc($doQuery)) {
$total_miles = $rows['total_miles'];
}
$num_rows = mysqli_num_rows($doQuery);
echo "<td id='" . $day_count . $row_number . "' value='" . $total_miles . "'
>
<form method='post' action='/test/day.php'>
<input type='hidden' value='" . $day_num . "' name='day'>
<input type='hidden' value='" . $title . "' name='month'>
<input type='hidden' value='" . $year . "' name='year'>
<input type='button' id='dayNum' value='" . $day_num . "'>
</form>
<span id='totalMiless'>Total miles: ";
if($num_rows == 1) {
echo $total_miles;
}
else {
echo '-';
}
echo "</span>
</td>
<div class='hiddenDay' id='" . $day_num . $title . $year . "' style='display:none'>
<span id='totalMiles'>Total miles: ";
if($num_rows == 1) {
echo $total_miles;
}
else {
echo '0';
}
echo "</span></div>";
if(is_numeric($total_miles)) {
$weekly_total[] = $total_miles;
}
$week_total_mileage[$day_num] = $total_miles;
$day_num++;
$day_count++;
if ($day_count > 7) {
$total_total = 0;
while($x < 8) {
$total_total = $total_total + $week_total_mileage[$x];
$x++;
}
while($x < 14 && $x > 8) {
$total_total = $total_total + $week_total_mileage[$x];
}
echo "<td>" . array_sum($weekly_total) .
"</td></tr><tr id='row" . $row_number . "'>";
empty($week_total_mileage);
$weekly_total = array();
$day_count = 1;
$row_number++;
}
}
//Finaly we finish out the table with some blank details if needed
$end_days = 1;
while ( $day_count >1 && $day_count <=7 ) {
echo "<td><span id='endDays'>" . $end_days . "</span></td>";
$day_count++;
$end_days++;
}
echo "</tr></table>";
?>
</body>
</html>

Categories