【问题标题】:Use SQL TimeDiff to populate PHP table data使用 SQL TimeDiff 填充 PHP 表数据
【发布时间】:2012-12-29 01:12:42
【问题描述】:

我已经在 Google 上搜索了很长时间,但我不知道这是我提出问题的方式还是什么,但我找不到任何与此密切相关的内容。我有一个 PDO SQL 语句:

 try 
    {
$query = $dbh->prepare("SELECT id, anum, first, last, signintime, counselorname, 
                        finishtime, TIMEDIFF(finishtime, signintime) AS Total_wait  FROM inoffice;");
$query->execute();
$result = $query->fetchall();
    }
        catch (PDOException $e) {
        error_log($e->getMessage());
        die($e->getMessage());
        }

然后我有一个结构如下的表:

<table id='datatables' class='display'>
                <thead>
                    <tr>

                        <th>Session Id</th> 
                        <th>A Number</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Signin Time</th>
                        <th>Counselor Name</th>
                        <th>Finish Time</th>
                        <th>Total Wait Time</th>
                    </tr>
                </thead>
                <tbody>
                 <?php
                    foreach($result as $row) {
                        ?>
                        <tr>
                            <td><?=$row['id'] ?></td>
                            <td><?=$row['anum'] ?></td>
                            <td><?=$row['first'] ?></td>
                            <td><?=$row['last'] ?></td>
                            <td><?=$row['signintime'] ?></td>
                            <td><?=$row['counselorname'] ?></td>
                            <td><?=$row['finishtime'] ?></td>
                            <td><?= ?></td>
                        </tr>
<?php
}
?>            

                    </tbody>
            </table>

我的问题是我到底如何在我的表的最后一个 td 标记中获得我的 PDO 选择的最后部分?我感到困惑的部分是:

TIMEDIFF(finishtime, signintime) AS Total_wait

我希望它能够包含在表格的最后一个 td 中。任何帮助/技巧/解决方法都很棒。

【问题讨论】:

    标签: php mysql datetime pdo html-table


    【解决方案1】:

    你必须对待TIMEDIFF(finishtime, signintime) AS Total_wait

    作为数据库中自己的行。

    导致:

     <td><?=$row['Total_wait'] ?></td>
    

    现在这张桌子看起来很好用:

    【讨论】:

      猜你喜欢
      • 2016-07-03
      • 2016-07-31
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多