我正在做一个学校项目,我必须从一个数组创建一个时间表。我已经按天计算了数组。时间。我知道如何创建一个简单的表并插入数据 - 但我想制作一个与时间有关的更明确的表:
星期一的数组如下所示:
数组([0] =>数组([courseID] => comp275 [讲义] => gg [日] =>星期一[stime] => 12:15 [etime] => 15 :16 [term] => winter [year] => 2014)[1] =>数组([courseID] => comp345 [讲义] => ss [day] => monday [stime] = > 18:20 [etime] => 20:30 [term] => winter [year] => 2014))
我希望表格对于“星期一”列
是这样的table type http://4.ii.gl/mtHVQN.png
这是我目前的代码(它有点破碎,但我还没弄清楚如何做我真正想要的东西。)
<table>
<tr>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
</tr>
<?php getMonday($Array); ?>
</table>
功能:
foreach($Array as $MA)
{
echo
"<tr class='success'><td>".
"Start-Time :".$MA["stime"]." "
."<br><br>".
"Course :".$MA["courseID"]." "
."<br><br>".
"End-Time :".$MA["etime"]." "
."</td></tr>";
}
给我这个:
答案 0 :(得分:0)
您可以为每个班级创建div
,而不是在日期列中使用单元格,而是根据时间更改高度。例如 -
$curr_time = strtotime('08:00'); //beginning of the day
foreach($Array as $MA) {
// create a blank div if it does not equal $curr_time
if(strtotime($MA['stime']) != $curr_time){
$empty_size = // get size for difference between $MA['stime'] and $curr_time
echo "<div style='height:{$empty_size}px;'></div>";
}
// create the div for the class time
$div_size = // get size for difference between $MA['etime'] and $MA['stime']
echo "<div class='success' style='height:{$div_size}px;'>".
// your data
"Start-Time :".$MA["stime"]." "
."<br><br>".
"Course :".$MA["courseID"]." "
."<br><br>".
"End-Time :".$MA["etime"].
// end of your data
"</div>";
// change the $curr_time to $MA['etime']
$curr_time = strtotime($MA['etime']) ;
}
由于这是一个学校项目,我不会给你所有的代码/完整的工作示例,只是这个示例代码/想法。您需要根据时间差异找到确定div
s高度的方法。希望这会有所帮助。