简体   繁体   中英

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. I have a PDO SQL statement :

 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? 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. Any help / trick / work around be awesome.

You must treat 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 :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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