好吧,我敢肯定有一種方法可以做到這一點,但我患有睡眠剝奪,真的可以使用一些幫助。列出所有記錄下月份作爲表格
這是我需要的。我有一個表頭和下面列出的數據行 - 它看起來不錯,但我需要在月份更改以分隔出月份時在數據行之間添加一個表格行。
這是我有:
Date Time Event
08-31-2013 6:00 pm EST Horseshoe Tourney
09-07-2013 8:00 pm EST Movie Night
09-28-2013 5:00 pm EST Dinner on the Quad
10-12-2013 4:30 pm EST Sing-a-long
10-31-2013 7:00 pm EST Halloween Party
11-14-2013 4:00 pm EST Hay Ride
這就是我需要:
Date Time Event
AUGUST (to span the whole table row)
08-31-2013 6:00 pm EST Horseshoe Tourney
SEPTEMBER (to span the whole table row)
09-07-2013 8:00 pm EST Movie Night
09-28-2013 5:00 pm EST Dinner on the Quad
OCTOBER (to span the whole table row)
10-12-2013 4:30 pm EST Sing-a-long
10-31-2013 7:00 pm EST Halloween Party
NOVEMBER (to span the whole table row)
11-14-2013 4:00 pm EST Hay Ride
任何幫助將不勝感激。下面是我用來創建表格的代碼。
<table style="width: 100%;">
<thead>
<tr style="background-color:#8a0028; color:white;">
<th style="background-color:#8a0028; color:white; text-align:left;">Date</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Time</th>
<th style="background-color:#8a0028; color:white; text-align:left;">Event</th>
</tr>
</thead>
<tbody>
<?php
// Write rows
mysql_data_seek($result, 0);
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
這是什麼結束了爲我工作!當然,請欣賞幫助!
<?php
// Write rows
mysql_data_seek($result, 0);
$month='';
while ($row = mysql_fetch_assoc($result)) {
if(date("F", strtotime($row['date']))!==$month){
$month=date("F", strtotime($row['date'])); ?>
<tr><td colspan="3"><?= $month ?></td></tr>
<?php
}
?>
<tr>
<td><?php echo date("M d, Y", strtotime($row['date']));?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['event'];?></td>
</tr>
<?php
$month=date("F", strtotime($row['date']));
}
?>
</tbody>
</table>
<?php
mysql_free_result($result);
?>
感謝皮特Bekisz - 我試圖找出如何讓這些排隊。顯然,這是我第一次使用Stackoverflow。 – user2833089
不用擔心!我們一直在那裏:) – Pete