简体   繁体   English

在HTML表中显示日期

[英]Display Date In HTML Table

I am querying SQL Server and creating a table of the result set from the query. 我正在查询SQL Server并从查询中创建结果集的表。 The first two fields in my table display as they should, however the date field is always left blank, which leaves me to see that this field is my issue. 表中的前两个字段应按原样显示,但是date字段始终保留为空白,这使我无法确定此字段是我的问题。 Below is the issue syntax - how should I alter it so that it will actually display my date field in the table? 下面是问题的语法-我应该如何更改它以便它实际在表中显示我的日期字段?

    $query->select($db->quotename(array('UnitID,SaleAmt,SaleDate')));
    $query->from($db->quoteName('SaleInformation'));
    $datefield_name = $db->quoteName('SaleDate');
    $query->where("$datefield_name >= " . $db->quote($startdate), 'AND');
    $query->where("$datefield_name <= " . $db->quote($enddate));
} else {
    echo "Please check the selection criteria and process again.";
}
$db->setQuery($query);
$query = $db->loadObjectList();
?>
<div id="dvdata">
    <table id="example" border="1" >
        <thead>
            <tr>
                <th>Job Number </th>
                <th>SaleAmt </th>
                <th>Sale Date</th>
            </tr>
        </thead>
        <?php
        foreach ($query as $res) {
            print "<tr>";
            print "<td><a href='http://internallocalhost/test" . $res-> . "' target=_blank>" . $res->UnitID . "</a></td>";
            print "<td>" . "$" . number_format(round($res->SaleAmt)) . "</td>";
            print "<td>" . date('d-m-Y', strtotime($res['SaleDate'])) . "</td>";
            print "</tr>";
        }
    }
    ?>

I think you just treat wrongly object as an array 我认为您只是将object错误地视为array

$query = $db->loadObjectList(); $ query = $ db-> loadObjectList(); Load the results as a list of stdClass objects So try like this way. 将结果作为stdClass 对象的列表加载,因此请尝试这种方式。

 print "<td>" . date('d-m-Y', strtotime($res->SaleDate)) . "</td>";

I also have a doubt about the syntax $res-> on the line, 我对在线上的$ res->语法也有疑问,

print "<td><a href='http://internallocalhost/test" . $res-> . "' target=_blank>" . $res->UnitID . "</a></td>";

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

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