开发者

Output Loop using Queries Between PK

开发者 https://www.devze.com 2023-04-10 19:49 出处:网络
User Table Listing Table Merchant Table Merchant offer Table I\'m trying to get for each listing (aka listID) the listTitle, listCmt, but for each row where the listID in listing table equals t
  • User Table

    Output Loop using Queries Between PK

  • Listing Table

    Output Loop using Queries Between PK

  • Merchant Table

    Output Loop using Queries Between PK

  • Merchant offer Table

    Output Loop using Queries Between PK

I'm trying to get for each listing (aka listID) the listTitle, listCmt, but for each row where the listID in listing table equals the listID in the MerchantOffer (moID PK).How do I iterate through all those matches in mysql using php?

I tried using:

<?php
$result = $sth->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>";
}   
?>

SQL

   SELECT listTitle, listLength, listCmt, listDt
    FROM User U, Listing L, Merchant M, MerchantOffer MO
    WHERE U.uID = L.uID
    and L.listID = MO.listID
    and M.mID = MO.mId
    GROUP BY listTitle
    ORDER BY listDt DESC;

But, it doesnt give me what I want like:

   Title: Apple iPhone 4S (listTitle)
    Days: <some day amount <listLength>
    Comment: some comment <listCmt>

    Offer By: some user <mBCFName mBCLName>
    Offer:19.99 <moAmt>
    Date: 10/03/2011 < moDtOff>

    Offer By: some user <mBCFName mBCLName>
    Offer:19.99 <moAmt>
    Date: 10/03/2011 < moDtOff>

    Offer By: some user <mBCFName mBCLName>
    Offer:19.99 <moAmt>
    Date: 10/03/2011 < moDtOff>

    Offer By: some user <mBCFName mBCLName>
    Offer:19.99 <moAmt>
    Date: 10/03/2011 < moD开发者_开发问答tOff>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号