简体   繁体   中英

add mysql query to virtuemart

I'm new to virtuemart.

While trying to add hits to virtuemart products I create new filed in "jjws5_virtuemart_products" in database and called it views .

Then I added my PHP code to the place I need it to appear in.

templates/mytemplate/html/com_virtuemart/productdetails/default.php:

<?php //views hits
    mysql_query("UPDATE jjws5_virtuemart_products SET views=views+1 WHERE virtuemart_product_id = '$virtuemart_product_id'");
    $views_hits = mysql_query("SELECT views FROM jjws5_virtuemart_products WHERE virtuemart_product_id = '$virtuemart_product_id'");
    while($total_views = mysql_fetch_array($$views_hits)){
        echo "Hits: ".$total_views['views'];
    }
?>

However, it's not showing anything.

What should I do to show it?

You use a variable variable to fetch result (maybe only a typo).

Change:

while($total_views = mysql_fetch_array($$views_hits))

in:

while($total_views = mysql_fetch_array($views_hits))

And, in the future, remember to activate error checking in our php code:

error_reporting( E_ALL );
ini_set( 'display_error', 1 );

With error checking, our original code produce this error:

PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in (...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM