----- 更新SQL
SELECT listTitle, listLength, listCmt, listDt,GROUP_CONCAT(mBCFName, mBCLName, moAmt) AS mOfferInfo
FROM User U
INNER JOIN Listing L on (U.uID = L.uID)
INNER JOIN MerchantOffer MO ON (L.listID = MO.listID)
INNER JOIN Merchant M on (M.mID = MO.mId)
GROUP BY listTitle
ORDER BY listDt DESC
LIMIT 0,5
腓
<?php
$result = $sth1->fetchAll(PDO::FETCH_ASSOC);
require_once('inc/php/timeAgo.php');
echo $then;
foreach($result as $row)
{
echo "<div class='listing'>";
print '<br>Title: ' . $row['listTitle'] . '<br>Comment: ' . $row['listCmt'] .
'<br><br>' . $days . ' days ' . $hours . ' hours ago' . '<br><br>' . '<br>Offer By: ' . $row['mBCFName']. ' ' . $row['mBCLName'] . '<br> for: ' . $row['moAmt'];
echo "</div>";
}
unset($sth1);
?>
提供如下输出: http://i.stack.imgur.com/sgdhC.png(管理员请展示)
现在输出正常,但我需要格式化一下。之后如何在mBCFName和mBCLName以及 space 之间添加空间。 (见上图)
答案 0 :(得分:0)
您是否已将数组$ result转出以查看实际返回的内容?我总是用以下方法测试它们:
echo '<pre>'.print_r($result,true).'<pre>';
我想把它添加为评论我还不能。很抱歉将其发布为“回答”。它应该显示如下:
array
(
['key1'] => 'value1'
['key2'] => 'value2'
['key3'] => 'value3'
['key4'] => 'value4'
)
答案 1 :(得分:0)
尝试删除:
GROUP BY listTitle
我认为这将返回您想要查看的所有行,但PHP代码不会产生您期望的输出。