Jump to content

Help troubleshoot sql query in hook function please?


Inetbiz

Recommended Posts

<?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 by Inetbiz
Link to comment
Share on other sites

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, '');

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated