Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Reviews in Product Info


PupStar

Recommended Posts

I have added the code for 'reviews in product info' but I can not seem to cure this error if there are no product reviews.

 

Warning: Division by zero in C:\wamp\www\store\product_info.php on line 206

 

It has me totally stumped wacko.png

 

I would appreciate it if one of you kind chaps would take a look for me.

 

The line in question from the code below is this:

 

$review_average = ($review_rating_total / $review_count);

 

Thanks

 

Mark

 

<!--Begin Product Reviews-->
<?php
$query = "SELECT reviews_id FROM " . TABLE_REVIEWS . " WHERE products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and reviews_status = 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$review_count=0;
while ($col = mysql_fetch_array($result, MYSQL_ASSOC)) {
 $review_count++;
}
mysql_free_result($result);$query = "SELECT sum(reviews_rating) FROM " . TABLE_REVIEWS . " WHERE products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and reviews_status = 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($col = mysql_fetch_array($result, MYSQL_ASSOC)) {
 foreach ($col as $col_value) {
 $review_rating_total = $col_value;
 }
}
mysql_free_result($result);
 $review_average = ($review_rating_total / $review_count);
 $review_average_total = $review_average;
 $review_average_total = number_format($review_average_total,1) . '/' . '5' . ' Stars';
 $review_average = number_format($review_average,0);if ($review_average) {
echo sprintf('<strong>' . TEXT_REVIEW_AVERAGE . '</strong>', ' ' . tep_image(DIR_WS_IMAGES . 'stars_' . $review_average . '.gif'), ''), ' ' . '<strong>' . $review_average_total . '</strong>';
} else {
echo TEXT_REVIEW_NO_RATING;
}
?>
<br />
<?php
$reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and r.reviews_status = 1 and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "'");
$reviews = tep_db_fetch_array($reviews_query);
?>
<strong><?php echo TEXT_REVIEW; ?></strong><?php echo ' ' . '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()) . '">' . '(' . $reviews['count'] . ')' . ' <em>' . TEXT_REVIEW_SHARING . '</em></a>'; ?>
<br />
<!--End Product Reviews-->

Link to comment
Share on other sites

try www3.schools.com

 

You need something like

 

if ($review_count == 0) ){

$review_average = 0;

 

} else {

$review_average = ($review_rating_total / $review_count);

}

 

cheers

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

try www3.schools.com

 

You need something like

 

if ($review_count == 0) ){

$review_average = 0;

 

} else {

$review_average = ($review_rating_total / $review_count);

}

 

cheers

 

G

 

Cheers G,

 

I had something like that except I was trying to do it as < instead of ==

 

You had 1 extra ) but we wont bother mentioning that blush.png

Link to comment
Share on other sites

Hope "something like" excuses my mistake innocent.gif

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...