People are voting by Stars on products. 1 - 5.
I want to show on this page, only those that are a 5 star average, (or 4 star average perhaps), and then select the product information to display it on screen.
Code: Select all
echo "<div class='sectionhomehead'>Recommended by you - our customers</div>";
$rating = mysql_query ("SELECT prodid, AVG(stars) FROM rating GROUP BY prodid") or die (mysql_error());
while ($rat = mysql_fetch_array($rating))
{
$starrating = number_format($rat['AVG(stars)']);
if ($starrating == "5") {
$product = mysql_query ("SELECT id, catid, subid, catname, subname, photoprimary, title, price FROM products WHERE id = $rat['prodid']");
while ($row = mysql_fetch_object($product))
{
echo "<div class='cat_prodlistbox'><a href='index.php?page=product&product=$row->id&s=$row->subid&c=$row->catid&cname=$row->catname&sname=$row->subname&menu=sub&head=$row->title' style='text-decoration: none'>";
if ($row->photoprimary == NULL) { echo "<img src='images/blank.gif' border='0' width='130px' height='101px' />";}
elseif ($row->photoprimary != NULL) { echo "<img src='images/productphotos/small/$row->photoprimary' width='130px' height='101px' border='0' />";}
echo "<br/>
$row->title<br/>Only ";
printf ("£%.2f", $row->price);
echo "<br/><img src='images/stars5.png' width='105px' border='0' /></a></div>";
}
} mysql_free_result($product);
} mysql_free_result($rating);EDIT: Or can you do a query that selects everything from the Ratings table where the AVERAGE is 5?Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\phpMyAdmin\site\includes\home.inc on line 42