gpt4 book ai didi

php - 列出表中包含日期信息的行

转载 作者:行者123 更新时间:2023-11-29 03:08:33 25 4
gpt4 key购买 nike

我正在开始构建一个简单的缺勤脚本,供教师管理学生。

我需要在 5 个表中填充相同的学生列表。本周的每一天(周一至周五)一张 table 。

我现在有以下代码

列出学生 SQL 查询:

SELECT s.student_id, s.student_firstname, s.student_lastname, 
a.student_absence_startdate, a.student_absence_enddate, a.student_absence_type
FROM students s
LEFT JOIN studentabsence a ON a.student_id = s.student_id
WHERE a.student_absence_startdate
IS NULL OR
'2012-06-20'
BETWEEN
a.student_absence_startdate AND a.student_absence_enddate

此查询选择所有学生并加入另一个表,该表是一个包含学生缺勤信息的链接表。

我像这样填充代码 5 次:

<?php
$data = array();
while ($row = mysql_fetch_array($list_students)) {
$data[] = $row;
}
?>

<table>
<?php
foreach($data as $row){
$class = "";
if ($row['student_absence_type'] == 2) {$class = " style='background:#f00;'";}
else if ($row['student_absence_type'] == 3) {$class = " style='background:#8A2BE2;'";}

echo "<tr><td$class>";
echo "<a class='ajaxlink' href='#' rel='pages/ajaxAbsence.php?student_id=".$row['student_id']."'>".$row['student_firstname']." ".$row['student_lastname']."</a>";
echo "</td></tr>\n";
}
?>
</table> <!-- Repeat -->

我的问题是我应该如何管理日期函数。

正如您在我的 SQL 查询中看到的那样,我对日期进行了硬编码。我需要它来自动选择列出学生的表格的日期。

例如:

table > Monday (2012-07-23)
the user John Doe has absence information in this span, based on the above query. Let's change the background of <td>
table > Tuesday (2012-07-24)
the user John Doe has no absence information in this span. Just list him.
etc...

我不希望您编写我的代码。我只是好奇如何思考。我对编程还很陌生。

最佳答案

我在您的想法中发现的最明显的错误是您不需要那五个表。您最终会重复和弄乱数据。

您需要与我读过的不同的表格。

学生

身份证、姓名等。

class_id, 名称,

教师

Id_teacher、姓名等

TeachersInClass(这样您现在就可以知道哪些老师教授了特定的类(class))

id, id_teacher, id_class

缺席

id, id_student, id_class, 日期

这为您提供了一个更强大的数据库,并且您可以使用多种关联进行游戏,例如一年中哪些老师缺勤最多......等等。

编辑:忘记回答您的“真实”问题。

您可以使用 PHP DateTime类来操纵你的日期。它易于使用,并且 php.net 有很多很好的示例可以帮助您快速入门

关于php - 列出表中包含日期信息的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11685999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com