繁体   English   中英

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

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

我有这张非常简单的桌子

http://gyazo.com/4ef60f33b16b43884ab64d9db23f18e3

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

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

我目前有2个约会

gyazo.com/f6d7020842e1cbafa75f9295340ad49b

我也有一个考勤表

gyazo.com/f88659eef625a14ee41fbe1f4ed30ab2

参加= 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>

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

我猜这将以最佳方式解决您的问题。 您应该创建一个表Attenance_has_eventdate(如果您的表以此方式命名),则该表与两个表均具有1:n的关系。

我建议您使用MySQL Workbench。 使用此工具,您可以很好地设计数据库,并且是免费的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM