获取循环以通过与 listID 关联的 mID 进行交互
----- 更新的 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
<?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);
?>
给出如下输出: https://i.sstatic.net/sgdhC.png(管理员请显示)
现在输出很好,但我需要稍微格式化一下。如何在 mBCFName 和 mBCLName 之间添加空格以及之后的空格。 (见上图)
----- 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 BY 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:
https://i.sstatic.net/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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试删除:
我认为这将返回您想要查看的所有行,但 PHP 代码不会产生您期望的输出。
Try removing:
I think this will return all the rows you want to see, but the PHP code won't produce the output you expect.
您是否转储了数组 $result 以查看实际返回的内容?我总是用以下内容来测试它们:
我会将其添加为“我还不能”的评论。很抱歉将其发布为“答案”。它应该向您显示类似以下内容:
Have you dumped out the array $result to view what is actually returned? I always test them with:
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: