11-Oct-2012, 06:15 PM
On my site each product page has a comment form and my goal here is to get the average rating and put it on the product listing page,
here's what I have but I get an invalid argument error:
here's what I have but I get an invalid argument error:
PHP Code:
<?php
function get_product_rating() {
foreach ($products as $product) {
function cmtx_average_rating() { //get average rating
global $cmtx_mysql_table_prefix, $cmtx_page_id; //globalise variables
$result = mysql_query("SELECT AVG(rating) FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `is_approved` = '1' AND `rating` != '0' AND `page_id` = '$cmtx_page_id'");
$average = mysql_fetch_assoc($result);
$average = round($average["AVG(rating)"] / 0.5) * 0.5;
return $average;
}
}
}