Results 1 to 4 of 4

Thread: Help troubleshoot sql query in hook function please?

  1. #1
    Join Date
    Mar 2008
    Location
    New Smyrna Beach, FL US
    Posts
    252

    Default Help troubleshoot sql query in hook function please?

    Code:
    <?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","");}
    ?>
    Last edited by Inetbiz; 07-01-12 at 11:16 AM.
    StrikeHawk eCommerce, Inc.
    open source e-commerce developer on the osCommerce platform. ADD us to youtube youtube channel

  2. #2
    Join Date
    Mar 2008
    Location
    New Smyrna Beach, FL US
    Posts
    252

    Default

    I'm getting empty results
    StrikeHawk eCommerce, Inc.
    open source e-commerce developer on the osCommerce platform. ADD us to youtube youtube channel

  3. #3
    Join Date
    Mar 2008
    Location
    New Smyrna Beach, FL US
    Posts
    252

    Default

    Data Sample:

    Code:
    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, '');
    StrikeHawk eCommerce, Inc.
    open source e-commerce developer on the osCommerce platform. ADD us to youtube youtube channel

  4. #4
    Join Date
    Mar 2008
    Location
    New Smyrna Beach, FL US
    Posts
    252

    Exclamation Updated and fixed somewhat

    Code:
    <?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.
    StrikeHawk eCommerce, Inc.
    open source e-commerce developer on the osCommerce platform. ADD us to youtube youtube channel

Similar Threads

  1. SQL query to change all customers currency to the same?
    By jmginer in forum General Discussion
    Replies: 4
    Last Post: 02-02-13, 04:32 PM
  2. sql query nested replace for seo links in articles
    By Nullified in forum Customisation & Integration Questions
    Replies: 0
    Last Post: 10-01-12, 03:20 AM
  3. Need an SQL Query - ready to pay!
    By handsonwebhosting in forum Customisation & Integration Questions
    Replies: 2
    Last Post: 10-07-10, 12:32 AM