I am trying to print Calender Weeks from 1-52 in a table with their starting and ending date,
now I want to add some users of my database (database holds 15 users):
Code:
<tbody>
<?php
$currentYear = date('Y');
$kw = CalenderWeekHelper::getCalenderWeek($currentYear);
for ($i=1; $i <= 52; $i++) {
foreach($resultRand as $result) {
?>
<tr>
<td>
<?php echo $i; ?>
</td>
<td colspan="2">
<?php echo $kw[$i]['start'].' - '.$kw[$i]['end']; ?>
</td>
<td>
<?php echo $result['user']; ?>
</td>
</tr>
<?php
}
}
?>
</tbody>
Helper Class looks like this (works):
<?php
class CalenderWeekHelper {
public static function getCalenderWeek($year)
{
for ($i=1; $i <= 52; $i++)
{
$week = sprintf('%02s', $i);
$from = date("d.m.Y", strtotime("{$year}W{$week}"));
$to = date("d.m.Y", strtotime("{$year}W{$week} +6 days"));
$weekArray[$i] = array('start' => $from, 'end' => $to);
}
return $weekArray;
}
}
?>
This gives me something like this:
Calender Weeks | date | user
_______________________________________________________________
1 | 29.12.2014 - 04.01.2015 | Steven
2 | ... | Steven
3 | ... | Steven
4 | ... | Steven
5 | ... | Steven
6 | ... | Steven
7 | ... | Steven
8 | ... | Steven
9 | ... | Steven
10 | ... | Steven
11 | ... | Steven
... | ... | Steven
52 | ... | Steven
1 | 29.12.2014 - 04.01.2015 | Glenn
... | ... | Glenn
52 | ... | Glenn
The dates do work, but as you can see I cannot handle those 2 loops. It should look something like this:
Calender Weeks | date | user
_______________________________________________________________
1 | 29.12.2014 - 04.01.2015 | Steven
2 | ... | Glenn
3 | ... | Lisa
4 | ... | Jonn
5 | ... | Alex
6 | ... | Micheal
7 | ... | Sucre
8 | ... | T-Bag
9 | ... | Han
10 | ... | ...
11 | ... | ...
... | ... | ...
52 | ... | ...
Since I have only 15 users in my database, the names have to repeat but should repeat equally if possible.
Can anyone help me out?
Aucun commentaire:
Enregistrer un commentaire