Inetbiz Posted July 1, 2012 Share Posted July 1, 2012 (edited) <?php function init_ClientAreaPage($vars) { global $smarty; $sql_product_rating = mysql_query("SELECT * FROM mod_products_reviews WHERE active= 1 AND productid=".$vars['productid']); $votes = 0; $rating = 0; while ($productrating = mysql_fetch_array($sql_product_rating)) { $votes ++; $rating = $rating + $productrating["reviewrating"]; $avgrating = $rating / $votes; } $smarty->assign('revavg', $avgrating); $smarty->assign('revrate', $rating); add_hook("ClientAreaPage",1,"init_ClientAreaPage","");} ?> Edited July 1, 2012 by Inetbiz 0 Quote Link to comment Share on other sites More sharing options...
Inetbiz Posted July 1, 2012 Author Share Posted July 1, 2012 I'm getting empty results 0 Quote Link to comment Share on other sites More sharing options...
Inetbiz Posted July 1, 2012 Author Share Posted July 1, 2012 Data Sample: INSERT INTO `mod_products_reviews` (`id`, `productid`, `userid`, `username`, `reviewtitle`, `reviewtext`, `reviewrating`, `reviewdate`, `active`, `adminreply`) VALUES (1, 8, 106, 'John Doe', 'blah blah blah title', 'blah blah reviewtext', 5, 1313276172, 1, ''); 0 Quote Link to comment Share on other sites More sharing options...
Inetbiz Posted July 1, 2012 Author Share Posted July 1, 2012 <?php function init_ClientAreaPage($vars) { global $smarty; $sql_product_rating = mysql_query("SELECT * FROM mod_products_reviews WHERE active= 1 AND productid = ".$vars['product']['id']); while ($productrating = mysql_fetch_array($sql_product_rating)) { $votes = 0; $rating = 0; $votes ++; $rating = $rating + $productrating["reviewrating"]; } $avgrating = $rating / $votes; $smarty->assign('revavg', $avgrating); $smarty->assign('revrate', $rating); $smarty->assign('votes', $votes); } add_hook("ClientAreaPage",1,"init_ClientAreaPage",""); ?> but now vote value is 1 and not the sum total or rows which is 6 for that product id. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.