Reputation: 504
I am querying SQL Server and creating a table of the result set from the query. 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. 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>";
}
}
?>
Upvotes: 0
Views: 2097
Reputation: 38502
I think you just treat wrongly object
as an array
$query = $db->loadObjectList(); Load the results as a list of stdClass objects So try like this way.
print "<td>" . date('d-m-Y', strtotime($res->SaleDate)) . "</td>";
I also have a doubt about the syntax $res-> on the line,
print "<td><a href='http://internallocalhost/test" . $res-> . "' target=_blank>" . $res->UnitID . "</a></td>";
Upvotes: 1