Output Loop using Queries Between PK
- 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 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>
精彩评论