How to add a MySQL query to a Zen Cart page

Aug 2, 2011 | Zen Cart Tips | 0 comments

It took me a while to figure out how to write my own MySQL query with the correct PHP syntax that Zen Cart likes. I thought I’d share it with you.

For example. Lets say you want to find out how many reviews were made for a particular product and display the number on the product description page. You would use the following and place it on your /includes/templates/YOUR-TEMPLATE/templates/tpl_product_info_display.php page. Of course, modify the style to match your page.

<?php
$this_sku_sql_for_reviews = "SELECT COUNT(products_id) as products_id, status FROM reviews where products_id = '" . $_GET&#91;'products_id'&#93; . "'";
$this_sku_reviews = $db->Execute($this_sku_sql_for_reviews);        
    if($this_sku_reviews->fields['status'] == 1) {
        echo "<p align="center" style="font-size:10px;margin-bottom:5px;">". $this_sku_reviews->fields['products_id']." reviews</p>";
    }
?>

0 Comments

Submit a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.