Php 如何为插入的每个日期生成一行,并为添加的每个成员添加出席时段
我有一张非常简单的桌子 这是一个非常简单的MYSQLI-to-HTML表 基本上,我一直在为每个添加的日期添加行/列 我现在有两次约会 gyazo.com/f6d7020842e1cbafa75f9295340ad49b 我还有一张考勤表 gyazo.com/f88659eef625a14ee41fbe1f4ed30ab2 出席=1表示该人出席了活动 我最终希望它看起来像这样,对于每个添加的成员,它将为日期生成相同的列和行 现行代码Php 如何为插入的每个日期生成一行,并为添加的每个成员添加出席时段,php,html,mysqli,Php,Html,Mysqli,我有一张非常简单的桌子 这是一个非常简单的MYSQLI-to-HTML表 基本上,我一直在为每个添加的日期添加行/列 我现在有两次约会 gyazo.com/f6d7020842e1cbafa75f9295340ad49b 我还有一张考勤表 gyazo.com/f88659eef625a14ee41fbe1f4ed30ab2 出席=1表示该人出席了活动 我最终希望它看起来像这样,对于每个添加的成员,它将为日期生成相同的列和行 现行代码 <!DOCTYPE HTML PUBLIC "-//W3
<!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关系 我想这会以最好的方式解决你的问题。如果您的表以这种方式命名,您应该创建一个表Attention\u has\u eventdate 此表与两个表都有1:n关系
我向您推荐MySQL工作台。使用此工具,您可以免费设计数据库。按案例排序-这是我不知道的一些奇特的SQL,还是案例是您的专栏?它可能是某种奇特的SQL;我可能做得不对,但这是按等级排序的:p@Fred-ii-好的。因为大小写是MySQL保留字;只是说说而已@user3432493@mudasobwa谢谢OP的ORDER BY CASE让我很反感。主要问题是生成表,而不是数据库本身:p使用MySQL工作台,您可以直接将模型导出到数据库。在那里,您还可以导出sql语句以在应用程序中使用它