【问题标题】:Display Records by date via PHP using table通过 PHP 使用表格按日期显示记录
【发布时间】:2021-07-26 07:56:31
【问题描述】:

第一张图片是我在我的数据库中的记录,'enr_biometrics_id' 是一个 user_id,我只是这样命名它。没关系'log_no'

数据表

现在,我想显示从日期 2021-07-01 - 2021-07-15 开始的 enr_biometrics_id = '000000001' 的记录,就像下图使用并在日期 2021-07- 的无记录上显示空白一样01 - 2021 年 7 月 15 日。提前感谢您的帮助!

我现在有一个代码:

    <?php include('config/config.php'); ?>
<table border="1">
<tr>
    <th>Log Date</th>
    <th>Logs</th>
    <th>Logs</th>
    <th>Logs</th>
    <th>Logs</th>
    <th>Logs</th>
</tr>
<?php
$start_period = "2021-07-01";
$end_period = "2021-07-15";

date_default_timezone_set('UTC');

while (strtotime($start_period) <= strtotime($end_period)) {
    
?>
<tr>
    <td><?php echo "$start_period"; ?></td>
    <?php
    $logs_query = mysqli_query($conn, "SELECT * FROM tb_daily_time_record WHERE date_added BETWEEN '$start_period' AND '$end_period' AND enr_biometrics_id='000000001' ")or(die(mysql_error()));
        
            while($row_logs = mysqli_fetch_assoc($logs_query)){
                $date_logs = $row_logs['date_added'];
                $t_logs = $row_logs['time_log'];
    ?>
        <td>
        <?php 
            echo $t_logs;
        ?>
    </td>
    <?php 
        }
    ?>
</tr>
<?php 
 $start_period = date ("Y/m/d", strtotime("+1 days", strtotime($start_period)));
}
?>
<tr>
</table>

得到这样的结果MyCoderightnow

【问题讨论】:

  • 您的问题到底是什么?从数据库获取数据?构建 HTML?还有什么?
  • 向我们展示您尝试过的代码,并详细描述您遇到的问题。
  • 使用上述数据库中的记录以该格式将记录显示到 。
  • 这是一个要求,不是问题。你试过什么?你到底卡在哪里了?我们很高兴在这里为人们提供帮助,但这不是免费的“写我的代码”服务。在请求他人空闲时间之前,请证明您已经做出了自己的一些努力。另外请使用tour 并阅读How to Ask,以便您了解有关stackoverflow 工作原理的更多信息。
  • 我刚刚编辑了我上面的问题。抱歉早些时候我是新手.. MAX Logs 也是 5 列

标签: php html mysql


【解决方案1】:

这将是我对您提供的信息的解决方法。优化 thise 可能是可行的,但它提供了一个很好的解决方案。

总和,我检查当前行是否与之前的行有相同的字符串,如果不是,我创建一个新行

$result = 'SELECT * FROM table'; // query .. 

$checkdate='';

echo '<table>';
foreach ($result as $row) {
  if ($row['date_added'] != $checkdate) {
    $checkdate = $row['date_added'];

    echo '</tr>
    <tr>
    <td>'.$row['time_log'].'</td>
    <td>'.$row['time_log'].'</td>';
    continue;
  }
  echo '<td>'.$row['time_log'].'</td>';
} 
echo '</tr></table>';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 2016-08-03
    • 2020-08-17
    相关资源
    最近更新 更多