I've been asked to compile a page that shows all comments for each product, between a given set of dates.
So you might select June to August, and it will show each product that has comments, and their comments. The product details needs showing just once, with the comments next to that info.
At the moment I have it so that it shows each comment, and the photo - for every comment though!
I did think about a Join, but that would also show the photo each time it finds a comment.
There are over 2000 products so obviously I don't want it to be going thru all the products each time the page loads.
It's run by Admin, so there is no "spike" concerns.
Here is the code at the moment. Maybe it's a simple one. So you have the photo on the right, and then all the comments assigned to that product on the left.
Code: Select all
echo "<div class='blockheader'>Comments for this period</div>";
$result = mysql_query ("SELECT * FROM usercomments WHERE email LIKE '%@%' AND (dateentered BETWEEN '$datefrom' AND '$dateto') ORDER by dateentered DESC ");
while ($row = mysql_fetch_object($result))
{
echo "<div class='awards_comments'>";
$resultp = mysql_query ("SELECT photoprimary, title, catname, subname FROM products WHERE id = '$row->prodid'");
while ($rowp = mysql_fetch_object($resultp))
{
echo "<div class='awards_product'><img src='/images/productphotos/small/$rowp->photoprimary' /><br/>
$rowp->title<Br/>
$rowp->catname</div>";
}
echo "<div class='awards_comment'>$row->dateentered ($row->prodid, $row->prodname)<br/>$row->nickname<Br/>$row->email<Br/>($row->id) $row->usercomments</div>
<div style='clear: both' /></div>
</div>";