douqi2804 2014-10-06 18:15
浏览 38

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

i have this really easy table

http://gyazo.com/4ef60f33b16b43884ab64d9db23f18e3

This currently is a really simple MYSQLI to HTML table

basically im struggling with adding rows/columns for every date added

i currently have 2 dates

gyazo.com/f6d7020842e1cbafa75f9295340ad49b

i also have a attendance table

gyazo.com/f88659eef625a14ee41fbe1f4ed30ab2

attending = 1 meaning that the person is at the event

http://gyazo.com/c4bc3fdbc85c642bf45ec173019b7b60

i eventually want it to look like this and for every member added it will generate the same columns and rows for the dates

current code

<!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>
  • 写回答

1条回答 默认 最新

  • doushun4666 2014-10-06 18:24
    关注

    Did you try to use a n:m relation between the attendance and date table?

    This would solve your problem in the best way I guess. You should create a table attendance_has_eventdate (In case your tables are named this way) this table has an 1:n relation to both of your tables.

    I would recommend you the MySQL Workbench. With this tool you can design your DB quite good and it's for free.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题