簡體   English   中英

使用SQL TimeDiff填充PHP表數據

[英]Use SQL TimeDiff to populate PHP table data

我已經在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中。 任何幫助/技巧/解決方法都很棒。

您必須將TIMEDIFF(finishtime, signintime) AS Total_wait

作為數據庫中自己的行。

結果:

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

現在桌子看起來很不錯了:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM