Jump to content



Latest News: (loading..)

- - - - -

Reviews in Product Info

a little issue i need help

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#-19 ONLINE   PupStar

PupStar
  • Members
  • 560 posts

Posted 14 December 2011 - 01:20 PM

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.

Quote

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

It has me totally stumped [img]http://forums.oscommerce.com//public/style_emoticons/default/wacko.png[/img]

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


#-18   geoffreywalton

geoffreywalton

    Contact me for Support

  • Community Sponsor
  • 8,037 posts

Posted 15 December 2011 - 12:29 PM

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

#-17 ONLINE   PupStar

PupStar
  • Members
  • 560 posts

Posted 15 December 2011 - 12:47 PM

View Postgeoffreywalton, on 15 December 2011 - 12:29 PM, said:

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 [img]http://forums.oscommerce.com//public/style_emoticons/default/blush.png[/img]

#-16   geoffreywalton

geoffreywalton

    Contact me for Support

  • Community Sponsor
  • 8,037 posts

Posted 15 December 2011 - 12:50 PM

Hope "something like" excuses my mistake [img]http://forums.oscommerce.com//public/style_emoticons/default/innocent.gif[/img]

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