Get average rating of “user reviews” and “editor reviews” in JReviews.

Get average rating of “user reviews” and “editor reviews” in JReviews.
May 20, 2014

JReviews provides average rating either for “user reviews” or “editor reviews” but to get the average of all we can use this function .

function getAvgRating($locid)

{

$query = “SELECT SUM (ratings_sum) as rsum, SUM (ratings_qty) as rqty,count(#__jreviews_comments.id) as cnt “.
“FROM #__jreviews_ratings, #__jreviews_comments “.

“WHERE #__jreviews_ratings.reviewid = #__jreviews_comments.id AND #__jreviews_comments.published=1 AND

#__jreviews_comments.pid = ‘$locid'”;

/*$ratings = mysql_query($query);

$ratings_count = mysql_num_rows($ratings);*/

$db = JFactory::getDBO();

$db->setQuery($query);

$row = $db->loadRow();

if($size = “small”) {$style_suffix = _sm;}

if($row[0] != NULL)
{
$average = $row[0]/$row[1];
$average_percentage = ($average/5)*100;
}
else {
$average_percentage = ‘0’;
}

return $average;
}

Leave a comment

Your email address will not be published. Required fields are marked *