简体   繁体   English

使用SQL TimeDiff填充PHP表数据

[英]Use SQL TimeDiff to populate PHP table data

I have been searching Google for a good amount of time and I don't know if it is the way I am asking the question or what but I can not find anything even closely relevant to this. 我已经在Google上搜索了很长时间,但我不知道这是我问问题的方式还是什么,但是我找不到与此相关的任何东西。 I have a PDO SQL statement : 我有一个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());
        }

and then I have a table structured like so : 然后我有一个结构如下的表:

<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>

My question is how on earth do I get the final part of my PDO select in that final td tag of my table? 我的问题是,我到底如何在表的最终td标签中获得PDO选择的最后一部分? the part I am confused on is : 我感到困惑的部分是:

TIMEDIFF(finishtime, signintime) AS Total_wait

I want that to be able to be included in the last td of the table. 我希望能够将其包含在表的最后一个td中。 Any help / trick / work around be awesome. 任何帮助/技巧/解决方法都很棒。

You must treat TIMEDIFF(finishtime, signintime) AS Total_wait 您必须将TIMEDIFF(finishtime, signintime) AS Total_wait

as its own row from the database. 作为数据库中自己的行。

resulting in this : 结果:

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

now the table looks and works great : 现在桌子看起来很不错了:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM