获取循环以通过与 listID 关联的 mID 进行交互

发布于 2024-12-08 20:33:07 字数 1210 浏览 0 评论 0原文

----- 更新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧瑾黎汐 2024-12-15 20:33:07

尝试删除:

GROUP BY listTitle

我认为这将返回您想要查看的所有行,但 PHP 代码不会产生您期望的输出。

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.

在梵高的星空下 2024-12-15 20:33:07

您是否转储了数组 $result 以查看实际返回的内容?我总是用以下内容来测试它们:

echo '<pre>'.print_r($result,true).'<pre>';

我会将其添加为“我还不能”的评论。很抱歉将其发布为“答案”。它应该向您显示类似以下内容:

array
(
 ['key1'] => 'value1'
 ['key2'] => 'value2'
 ['key3'] => 'value3'
 ['key4'] => 'value4'
)

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'
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文