[英]php HTML timetable with messed up html cells
我想我在創建學校時間表時完全弄亂了 html 表我需要的是必需的時間表但是我得到的時間表是這樣的不正確的時間表
我的代碼是
// days of week array
$days = array(
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
7 => 'Sunday' );
//Selecting all the hours from lectures
$hours = DB::table('timetablelectures')->select('timetablelectures.id', 'timetablelectures.start_time')
->get();
$timetable = DB::table('timetable')->select('timetable.id', 'timetable.day', 'timetable.lecture_id', 'timetable.subject_id')
->get();
echo "<table>";
echo "<tr>";
echo '<td></td>'; // empty cell
foreach( $hours as $hh ) {
echo "<td>";
echo $hh->start_time;
echo "</td>";
}
echo "</tr>";
foreach( $hours as $hour ) {
foreach( $days as $day => $day_name ) {
echo "<tr>";
echo '<td>', $day_name, '</td>'; // day of the week
foreach( $timetable as $tt ) {
echo "<td>";
if( (int)$tt->day == $day and $tt->lecture_id == $hour->id ) {
echo $tt->subject_id;
}
echo "</td>";
}
echo "</tr>";
}
}
echo "</table>";
任何人都可以看看它,因為我一直在敲我的頭。 空單元格將顯示為“未分配”也很棒
做了一些谷歌搜索后
$days = array("1"=>"Monday", "2"=>"Tuesday", "3"=>"Wednesday", "4"=>"Thursday", "5"=>"Friday", "6"=>"Saturday", "7"=>"Sunday", );
$hours = DB::table('timetablelectures')->select('timetablelectures.id', 'timetablelectures.start_time')
->get();
$timetable = DB::table('timetable')->select('timetable.id', 'timetable.day', 'timetable.lecture_id', 'timetable.subject_id')
->get();
//SET UP SCHEDULE
$schedule = array();
foreach($timetable as $tt)
{
foreach($days as $x => $x_value)
{
if ( $tt->day==$x)
{
$schedule["{$x}"][$tt->lecture_id][] = $tt->subject_id;
}
}
}
// DISPLAY SCHEDULE, headers first
?>
<table border="1">
<tr><td align="center">Time</td>
<?php foreach ( $hours as $hour )
{
echo "<td> $hour->start_time </td>";
}
echo "</tr>";
foreach ( $days as $x => $x_value) {
echo "<tr><td>$x_value</td>";
// roll through days
foreach ( $hours as $hour ) {
echo '<td>';
// check for subjects in this slot
if ( isset($schedule[$x][$hour->id]) ) {
// and display each
foreach ( $schedule[$x][$hour->id] as $subject ) {
echo "$subject<br>";
}
}
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.