我正在做一个学校项目,我必须从数组创建一个时间表。我已经按日期和时间对数组进行了排序。我知道如何创建一个简单的表格并插入数据 - 但我想制作一个与时间相关的更明确的表格:
星期一的数组如下所示:
Array ( [0] => Array ( [courseID] => comp275 [lectureID] => gg [day] => 星期一 [stime] => 12:15 [etime] => 15:16 [term] = > 冬天 [年份] => 2014 ) [1] => Array ( [courseID] => comp345 [lectureID] => ss [day] => 星期一 [stime] => 18:20 [etime] => 20:30 [学期] => 冬天 [年份] => 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>";
}
给我这个:
最佳答案
您可以为每个类(class)创建 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
的高度。希望这会有所帮助。
关于PHP - 创建与时间相关的时间表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22900878/