如何为插入的每个日期生成一行,并为添加的每个成员添加一个参与时段


how to generate a row for every date inserted and add a attending slot for every member added

我有一个非常简单的表

http://gyazo.com/4ef60f33b16b43884ab64d9db23f18e3

目前这是一个非常简单的MYSQLI到HTML表

基本上我很难为每个添加的日期添加行/列

我目前有两个约会

gyazo.com/f6d7020842e1cbafa75f9295340ad49b

我还有一张考勤表

gyazo.com/f88659eef625a14ee41be1f4ed30ab2

出席=1,意味着该人员在活动

http://gyazo.com/c4bc3fdbc85c642bf45ec173019b7b60

我最终希望它看起来像这样,对于每个添加的成员,它将为日期生成相同的列和行

当前代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
        <head>  
                <title>Attendance System</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <body>
                <h1>Attendance System</h1>
                <?php
                        // connect to the database
                        include('connect-db.php');


                        // get the records from the database
                        if ($result = $mysqli->query("SELECT * FROM players ORDER BY CASE WHEN rank = 'Colonel' THEN 0 WHEN rank = 'Lieutenant-Colonel' THEN 1 WHEN rank = 'Major' THEN 2 WHEN rank = 'Captain' THEN 3 WHEN rank = 'Lieutenant' THEN 4 WHEN rank = 'Ensign' THEN 5 WHEN rank = 'Serjeant Major' THEN 6 WHEN rank = 'Colour Serjeant' THEN 7 WHEN rank = 'Serjeant' THEN 8 WHEN rank = 'Corporal' THEN 9 WHEN rank = 'Lance Corporal' THEN 10 WHEN rank = 'Private' THEN 11 WHEN rank = 'Recruit' THEN 12 END, rank"))
                        {
                                // display records if there are records to display
                                if ($result->num_rows > 0)
                                {
                                        // display records in a table
                                        echo "<table border='1' cellpadding='10'>";
                                        // set table headers
                                        echo "<tr><th>ID</th><th>Alias</th><th>Historical Name</th><th>Rank</th><th>Company</th><th>attending</th>";
                                        echo "</tr>";
                                        // close table headers
                                        while ($row = $result->fetch_object())
                                        {           

                                                // set up a row for each record
                                                echo "<tr>";
                                                echo "<td>" . $row->id . "</td>";
                                                echo "<td>" . $row->firstname . "</td>";
                                                echo "<td>" . $row->lastname . "</td>";
                                                echo "<td>" . $row->rank . "</td>";
                                                echo "<td>" . $row->company . "</td>";
                                                echo "<td> Attending </td>";
                                                echo "</tr>";
                                        }
                                        echo "</table>";
                                }
                                // if there are no records in the database, display an alert message
                                else
                                {
                                        echo "No results to display!";
                                }
                        }
                        // show an error if there is an issue with the database query
                        else
                        {
                                echo "Error: " . $mysqli->error;
                        }
                        // close database connection
                        $mysqli->close();
                ?>
        </body>
</html>

您是否尝试在考勤表和日期表之间使用n:m关系?

我想这将以最好的方式解决你的问题。您应该创建一个表attendance_has_eventdate(如果您的表是以这种方式命名的)此表与您的两个表都有1:n关系。

我向您推荐MySQL工作台。有了这个工具,你可以很好地设计你的数据库,而且它是免费的。