An "if" statement

Locked

Started by IDEASLady on 17 Nov 2010, 12:08 AM · Views: 532

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
17 Nov 2010, 12:08 AM
#1
IDEASLady avatar

IDEASLady

Totally Zenned

Join Date:
Aug 2005
Location:
Trujillo Alto, Puerto Rico
Posts:
1,456
Plugin Contributions:
4

An "if" statement

Hello my php nerdy friends, can someone tell me how do I change this code to make it to show up ONLY when there's a review present:

<?php 
  echo '<p class="reviewCount">';
  if ($flag_show_product_info_reviews_count == 1) {
    echo TEXT_CURRENT_REVIEWS . ' <strong>' . $reviews->fields['count'] . '</strong><br />';
    $stars_image_suffix = str_replace('.', '_', zen_round($reviews_average_rating->fields['average_rating'] * 2, 0) / 2); // for stars_0_5.gif, stars_1.gif, stars_1_5.gif etc.
    $average_rating = zen_round($reviews_average_rating->fields['average_rating'], 2);
    echo TEXT_CURRENT_REVIEWS_RATING . ' <strong>' . $average_rating . '</strong> ' . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $stars_image_suffix . '.gif', sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $average_rating));
  } else {
    echo '';
  }
  echo '</p>';

I know I have to insert something like:

if ($reviews->fields['count'] > 0 ) { ?>

I just don't know where and how exactly. :unsure:

Thanks in advance!

IDEASLady
IDEAS Creative Studio

Your image... our business!

17 Nov 2010, 5:23 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: An "if" statement

Depending on the select statement ... and I believe you are pulling the average rating add on from the main_template_vars.php ...

When there are no reviews, you should get:
$reviews_average_rating->fields['average_rating']

and it will be NULL ... when there are no ratings

Otherwise, you will get a value ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

17 Nov 2010, 5:40 AM
#3
IDEASLady avatar

IDEASLady

Totally Zenned

Join Date:
Aug 2005
Location:
Trujillo Alto, Puerto Rico
Posts:
1,456
Plugin Contributions:
4

Re: An "if" statement

:blink: Hey Linda, you are speaking Russian to me. Was I supposed to understand that? or you are just "thinking" out laud?

IDEASLady
IDEAS Creative Studio

Your image... our business!

17 Nov 2010, 5:57 AM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: An "if" statement

Your code includes

zen_round($reviews_average_rating->fields['average_rating'] * 2, 0) / 2

so $reviews_average_rating->fields['average_rating'] is available to it. If you use that to test for not null, it will only display when there are reviews.

if($reviews_average_rating->fields['average_rating']) {

  //your code from OP

}
17 Nov 2010, 6:16 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: An "if" statement

You could also just replace this line in your OPphp if ($flag_show_product_info_reviews_count == 1) { with this```php
if (($flag_show_product_info_reviews_count == 1) and $reviews_average_rating->fields['average_rating']) {

17 Nov 2010, 6:20 AM
#6
IDEASLady avatar

IDEASLady

Totally Zenned

Join Date:
Aug 2005
Location:
Trujillo Alto, Puerto Rico
Posts:
1,456
Plugin Contributions:
4

Re: An "if" statement

AWESOME!!! :hug: Worked like a charm... TY!

IDEASLady
IDEAS Creative Studio

Your image... our business!