还有其他方法可以像矩阵形式一样在 html 中打印 mysql table 吗?

Is there any other way to print mysql table in html like a matrix form?

我目前在一所大学工作project.The要求是将数据(主题,class,部分)打印到html [=32=中相应的日期和时间] 尽力达到要求,但 html table 只是再次打印并打印下一个值,我希望我的所有数据在单个 table 中打印到相应的日期和时间.

这是我的数据库的图像:

这是我不满意的输出:

这是我的查询:

<?php  
include "conn.php";
include ("/styles/faculty_menu.php");
session_start();
$uid=$_SESSION['userid'];
$cuid=strtoupper("$uid");
$qrun=mysql_query("SELECT * FROM login WHERE id='$cuid'");
$udata=mysql_fetch_assoc($qrun);
$q2run=mysql_query("SELECT * FROM schedule WHERE id='$cuid'");
$u2data=mysql_fetch_assoc($q2run);
$urole=$udata['role'];
$comp=strtoupper("$u2data[subject]");
$day = array("Monday", "Tuesday", "Wednessday", "Thursday", "Friday", "Saturday");
?>

我希望输出是单个 table,所有受尊重的数据都在相应的位置。

这是我的代码:

<div class="table-responsive">
<table class="table table-bordered">
    <tr>
        <th>
            <center>Day/Hour</center>
        </th>
        <?php 
            for ($i=1; $i <=8 ; $i++) { 
            ?>
        <th>
            <center><?php echo $i; ?></center>
        </th>
        <?php } ?>
    </tr>
    <?php
        while ($rows=mysql_fetch_assoc($q2run)) {
           for ($d=0; $d <6 ; $d++) { 
           ?>
    <tr>
        <th>
            <center><?php echo $day[$d]; ?></center>
        </th>
        <?php 
            for ($r=1; $r <=8; $r++) {

                ?>
        <td>
            <?php 
                if ($rows['day']==$day[$d] && $rows['hour']==$r) {
                    echo $rows['class'],$rows['section'],$rows['subject'];

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

我已经更改了您的代码的一些逻辑。希望这会奏效

<div class="table-responsive">
    <table class="table table-bordered">
        <tr>
            <th>
                <center>Day/Hour</center>
            </th>
            <?php 
            for ($i=1; $i <=8 ; $i++)
                echo '<th><center>'.$i.'</center></th>';
            ?>
        </tr>
        <?php
        for($d=0;$d<6;$d++){
        ?>
            <tr>
                <th>
                    <center><?php echo $day[$d]; ?></center>
                </th>

                <?php
                for ($r=1; $r <=8; $r++) {
                    echo '<td>';
                        while ($rows=mysql_fetch_assoc($q2run)) {
                            if($rows['day']==$day[$d] && $rows['hour']==$r)
                                echo $rows['class'],$rows['section'],$rows['subject'];
                        }
                    echo '</td>';
                }
                ?>
            </tr>
        <?php
        } 
        ?>

    </table>
</div>