I have a select with week numbers on my page, when I select a week number, the table header changes to the days in that specific week. When I want to display the whole month again (by selecting default in the week select) the header does not change for some reason. Here is my code:
function TableHeader($week, $month, $year){
if($week != "default")
{
for($i=1; $i<=7; $i++)
{
$Datum = date('d', strtotime($year."W".$week.$i))."\n";
echo "<th scope='col' id='CalendarTableHeader' style='text-align:center;'>".$Datum."</th>";
}
}
else
{
for($i = 1; $i <= $numDays; $i++)
{
echo "<th scope='col' id='CalendarTableHeader' style='text-align:center;'>".$i."</th>";
}
}
}
Other parts of code involved:
$numDays = monthDays($month, $year);
MonthDays function (working)
function monthDays($month, $year) {
return date("t", strtotime($year . "-" . $month . "-01"));
}//
The part where I call the function (working)
if(isset($_GET['week'])){
$week = $_GET['week'];
TableHeader($week, $month, $year);
}
The strange part of my problem is that when I remove this part of my code out of my else clause:
for($i = 1; $i <= $numDays; $i++)
{
echo "<th scope='col' id='CalendarTableHeader' style='text-align:center;'>".$i."</th>";
}
It just works fine by itself.. I hope you can help me.
for($i = 1; $i <= $numDays; $i++)
{
echo "<th scope='col' id='CalendarTableHeader' style='text-align:center;'>".$i."</th>";
}
I did not find $numDays
variable in your TableHeader
function.
function TableHeader($week, $month, $year, $numDays) {
// Your code here
}
I think it should be
$numDays = monthDays($month, $year);
if(isset($_GET['week'])){
$week = $_GET['week'];
TableHeader($week, $month, $year, $numDays);
}