【问题标题】:Date in column headers of attendance list出勤表列标题中的日期
【发布时间】:2021-07-03 12:16:10
【问题描述】:

我想制作一个考勤列表,其中输入表单中输入的日期放在右侧第​​ 3 列的标题中。在以下列的标题中,此日期增加了 7 天。

我有三个问题:

  1. 为什么标题中没有填写日期?
  2. 如何在if语句中插入html表格?
  3. 如何使日期列的宽度变大 1 个字符?

我创建了一个输入表单forum.php 和一个动作脚本gen-table.php

输入表单forum.php:

<!DOCTYPE html>
<html>
<style>
td, th {
  border: 4px solid lightblue;
  text-align: left;
  padding: px;
}
</style>
<h2> ATTENDANCE LIST </h2>
</head>
<body>
    <form action="gen-table.php" method="post">
    <p>
        <label for="startdate">Startdate:</label>
        <input type="date" name="startdate" id="startdate" />
        <input type="submit" value="Select and Activate" />
    </p>
</body>
</html>

动作脚本gen-table.php:

<!DOCTYPE html>
<html>
<style>
td, th {
  border: 4px solid lightblue;
  text-align: left;
  padding: px;
}
</style>
<h2> ATTENDANCE LIST </h2>
</head>

<?php
if (isset($_POST[startdate])) {
$day1 = date('d-m-Y',strtotime(startdate ."+0 Days"));
$day2 = date('d-m-Y',strtotime(startdate ."+7 Days"));
$day3 = date('d-m-Y',strtotime(startdate ."+14 Days"));
$day4 = date('d-m-Y',strtotime(startdate ."+21 Days"));
}
else
{
    echo "Select startdate";
}
?>

<table>

    <th>Lastname</th>
    <th>Firstname</th>
    <td><?php print $day1 ?>&nbsp;</td><td><?php echo $day2 ?></td><td><?php echo $day3 ?>&nbsp;</td><td><?php echo $day4 ?>&nbsp;</td>
</table>
</html>

【问题讨论】:

  • 您在浏览器查看此页面的源代码功能中看到了什么?

标签: php html date


【解决方案1】:

答案 1。 日期未正确生成。在strtotime() 中,您应该从$_POST 数组中传递值。

替换

date('d-m-Y',strtotime(startdate ."+0 Days"));
...

date('d-m-Y',strtotime($_POST['startdate'] . "+0 Days"));
...

答案 2. 你可以转储 html 表格,条件如下-

<?php if(condition is true): ?>
     html <table> goes here
<?php endif; ?>

答案 3。 问题令人困惑,但根据我的假设,您可以使用字体大小使文本变大或使用填充为文本提供大空间。

【讨论】:

  • 谢谢。有用。一问。我收到此警告:警告:使用未定义的常量 startdate - 假定为“startdate”(这将在 PHP 的未来版本中引发错误)。
  • 使用 $_POST["startdate"] 而不是 $_POST[startdate]。另一件事是,如果答案对您有帮助,您可以接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
  • 2021-04-15
  • 2021-06-25
  • 1970-01-01
  • 1970-01-01
  • 2021-11-10
  • 1970-01-01
相关资源
最近更新 更多