php html表条目使用多个循环

时间:2015-10-20 03:31:31

标签: php html

更新:我一直在尝试在php html中准备一个交叉表条目但是不能这样做。对于我表格中的空白主题,我想显示一个链接来编辑该单元格。

我的更新代码:

$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();

//设置时间表

$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>';

我需要Correct Table Structure而不是空白而是提供一个链接来编辑条目

0 个答案:

没有答案