我有多个行和列的$data
数组。每行在其他列中包含日期和其他信息。我使用foreach循环绘制每个<tr>
行(附加到$output
上)。现在,如何添加同一天的rowspan= $samedays
?
如果我将当前$row
日期与第二天进行比较,则行跨度最多不超过两天。或者我必须将其添加到每一行。我需要预先计算相同的每一天,然后将rowpan应用于第一行,并在第二天将<td>
留空。
下面附上未成功结果的图片:
values
4r-1 =一周中的4天,r-1 =行跨数。
foreach ( $data as $nr => $row ) {
//converting UTC date to USER TIME ZOME!
$utc_date = $row[ 'dateTime' ];
$date = new DateTime( $utc_date, new DateTimeZone( 'UTC' ) );
$date->setTimeZone( new DateTimeZone( $tzone ) );
$tzWeekDay = $date->format( 'N' ); //get DAY NUMBER
$WeekNr = $date->format( 'W' ); //get WEEK number
if ( isset( $data[ $nr + 1 ] ) ) {
$next_row = $data[ $nr + 1 ]; // next element
} else {
$next_WeekDay = 0;
}
$next_utc_date = $next_row[ 'dateTime' ];
$next_date = new DateTime( $next_utc_date, new DateTimeZone( 'UTC' ) );
$next_date->setTimeZone( new DateTimeZone( $tzone ) );
$next_WeekDay = $next_date->format( 'N' ); //get DAY NUMBER
if ( $tzWeekDay == $next_WeekDay ) {
$rowspan_nr++;
$rowspan = 'rowspan=';
} else {
$rowspan_nr = 1;
$rowspan = 'rowspan=';
}
$previousDay = $tzWeekDay;
$output .= '<tr >
<td>' . $nr . '-' . $WeekNr . '</td>
<td ' . $rowspan . '"" >' . $tzWeekDay . 'r-' . $rowspan_nr . '</td>
<td class="dateTime ' . $weekend . ' " id="' . $row[ "id" ] . '"><input class="datepick" type="text" value="' . $tzDate . '"></td>
<td>
</tr>