dpzp5127 2016-01-28 14:09
浏览 7

预定科目的时间表

i got it right though my problem now is how can i put a style on the table row that has the data inside it and much better if i can put rowspan to it so that it will look like one table row.

here is the output:

enter image description here

and here is my code:

<?php
    $db = new mysqli("localhost", "root", "", "bsu_db");
    if($db->connect_errno > 0){
        die('Unable to connect to database [' . $db->connect_error . ']');
    }   
    $times = ["7:00:00", "7:30:00", "8:00:00", "8:30:00", "9:00:00", "9:30:00", "10:00:00", "10:30:00", "11:00:00", "11:30:00", "12:00:00"];
    $days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    $SubjDay = array();
    $sqlSubjDay = "SELECT * FROM subject_day_tbl";
    $qrySubjDay = $db->query($sqlSubjDay);
    while($rowSubjDay = $qrySubjDay->fetch_assoc()){
        //array_push($SubjDay, $rowSubjDay['sub_day'], $rowSubjDay['start_time'], $rowSubjDay['end_time']);
        $SubjDay[] = $rowSubjDay;
    }
    json_encode($SubjDay);
?>
<table class="table table-bordered table-condensed">
    <thead>
        <tr>
            <th></th>
            <?php
                foreach ($days as $day ) {
                    echo "<th>$day</th>";
                }
            ?>
        </tr>
    </thead>
    <tbody>
    <?php    
        foreach ($times as $time) {                     
    ?>
    <tr>  
        <td><?php echo $time; ?></td>
        <?php
            foreach ($days as $day) {                                           
                echo "<td>";
                foreach($SubjDay as $sd){
                                            
                    if($day == $sd['sub_day'] && strtotime($time) >= strtotime($sd['start_time']) && strtotime($time) <= strtotime($sd['end_time'])){
                        echo $sd['sub_day'] , " " , $sd['start_time'] , " - " , $sd['end_time'];
                    }
                                            
                }
                echo "</td>";
            }

        ?>
    </tr>
    <?php        
        } 
    ?>                   
    </tbody>
</table>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)