----- UPDATED 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 B开发者_Python百科Y listDt DESC
LIMIT 0,5
Php
<?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);
?>
Gives output like: http://i.stack.imgur.com/sgdhC.png (ADMIN PLEASE SHOW)
It outputs fine now, but I need to format it a bit. How do I add a space between mBCFName and mBCLName and space after that. (see image above)
Try removing:
GROUP BY listTitle
I think this will return all the rows you want to see, but the PHP code won't produce the output you expect.
Have you dumped out the array $result to view what is actually returned? I always test them with:
echo '<pre>'.print_r($result,true).'<pre>';
I would add this as a comment by I can't yet. Sorry for posting it as an 'answer'. It should show you something like:
array
(
['key1'] => 'value1'
['key2'] => 'value2'
['key3'] => 'value3'
['key4'] => 'value4'
)
精彩评论