生成多个表(供查看)

atmip9wb  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(320)

我想问一下如何使我的table如下所示:

但我只能让我的table看起来像这样:

正如你所看到的,表格是根据不同的年份或学期分开的。它基本上是一个特定的人的历史存储。不幸的是,我不知道如何将生成的表附加到同一学年和学期的表中,而不是将其分开。甚至编号也会受到影响。以下是我目前掌握的代码:

<?php  
include("connect.php");
include("header.php");

if(isset($_GET['invstuview_bag'], $_GET['invstuview_name']))
{
    $get_id = $_GET['invstuview_bag'];  
    $get_name = $_GET['invstuview_name']; 

?>

<br/>
<ul class="breadcrumb">
    <li class="breadcrumb-item"><a href="view.php">View History</a></li>
    <li class="breadcrumb-item-active">Baggage Detail History</a></li>
</ul>
<div id="cssword">Baggage Detail History For <?php echo $get_name; ?>(<?php echo $get_id; ?>)</div>
<div class="container" style="width:70%;"> 
    <div class="table-responsive">
    <?php
        $sql_join = "SELECT student.*,location.*, inventory.*, baggage.*
                FROM 
                    student,location, inventory, baggage
                WHERE
                    student.student_id = inventory.invstu_id AND
                    baggage.baggage_id = inventory.invbag_id AND
                    location.location_id = inventory.invloc_id AND
                    invstu_id = '$get_id'
                ORDER BY inventory_id";

        $result_join= mysqli_query($connect,$sql_join); 

        $prev_year = "";
        $prev_sem = 0;
        $get_year = "";
        $get_sem = 0;
        while($row_join=mysqli_fetch_assoc($result_join))
        {
            $counter = 1;
            $prev_year =  $row_join["invstu_year"];
            $prev_sem =  $row_join["invstu_sem"];

            //if the data is of same year and semester
            if(($prev_year!="") && ($prev_sem!=0) && ($prev_year == $get_year) && ($prev_sem == $get_sem))
            {
                $get_year = $row_join["invstu_year"];
                $get_sem = $row_join["invstu_sem"];
    ?>
                <table class="table table-bordered">
                <tr>
                    <th>No.</th>
                    <th>Baggage Types</th>
                    <th>Quantity</th>
                    <th>Location</th>
                </tr>
                <tr>
                    <td><?php echo $counter; ?></td>
                    <td><?php echo $row_join["baggage_type"]; ?></td>
                    <td><?php echo $row_join["invbag_quantity"]; ?></td>
                    <td><?php echo $row_join["location_house"]; ?></td>
                    </tr>

                <?php
                $counter++; 
                echo'</table>';

            }
            //if data is not of same year or semester
            else
            {
                $get_year = $row_join["invstu_year"];
                $get_sem = $row_join["invstu_sem"];
            ?>
                </br></br>
                Room: <?php echo $row_join["invstu_room"]; ?><br/>
                Year: <?php echo $row_join["invstu_year"]; ?><br/>
                Semester: <?php echo $row_join["invstu_sem"]; ?><br/>

                <table class="table table-bordered">
                <tr>
                    <th>No.</th>
                    <th>Baggage Types</th>
                    <th>Quantity</th>
                    <th>Location</th>
                </tr>
                <tr>
                    <td><?php echo $counter; ?></td>
                    <td><?php echo $row_join["baggage_type"]; ?></td>
                    <td><?php echo $row_join["invbag_quantity"]; ?></td>
                    <td><?php echo $row_join["location_house"]; ?></td>
                    </tr>
                <?php
                    $counter++; 
                    echo'</table>';
            }
        }
            ?>
    </div>
    <div align="right">
            <button type="button" name="back" class="btn btn-success" id="back" style="width:200px; display:inline-block; margin-top:2%; margin-bottom:1%; background-color: #4CAF50" onclick="window.location.href='view.php'">Back</button>
    </div>

</div>
<?php
}
?>

任何想法都将受到高度赞赏。

fcwjkofz

fcwjkofz1#

将这些从while循环中移出:

<table class="table table-bordered">
            <tr>
                <th>No.</th>
                <th>Baggage Types</th>
                <th>Quantity</th>
                <th>Location</th>
            </tr>

           echo'</table>';

相关问题