Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2005
    Location
    Trujillo Alto, Puerto Rico
    Posts
    1,550
    Plugin Contributions
    9

    Default 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:
    Code:
    <?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:
    Code:
    if ($reviews->fields['count'] > 0 ) { ?>
    I just don't know where and how exactly.

    Thanks in advance!
    IDEAS Girl
    IDEAS Creative Group
    = Your image... our business!

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

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

  3. #3
    Join Date
    Aug 2005
    Location
    Trujillo Alto, Puerto Rico
    Posts
    1,550
    Plugin Contributions
    9

    Default Re: An "if" statement

    Hey Linda, you are speaking Russian to me. Was I supposed to understand that? or you are just "thinking" out laud?
    IDEAS Girl
    IDEAS Creative Group
    = Your image... our business!

  4. #4
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default 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.
    PHP Code:
    if($reviews_average_rating->fields['average_rating']) {

      
    //your code from OP



  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: An "if" statement

    You could also just replace this line in your OP
    PHP Code:
      if ($flag_show_product_info_reviews_count == 1) { 
    with this
    PHP Code:
      if (($flag_show_product_info_reviews_count == 1) and $reviews_average_rating->fields['average_rating']) { 

  6. #6
    Join Date
    Aug 2005
    Location
    Trujillo Alto, Puerto Rico
    Posts
    1,550
    Plugin Contributions
    9

    Default Re: An "if" statement

    AWESOME!!! Worked like a charm... TY!
    IDEAS Girl
    IDEAS Creative Group
    = Your image... our business!

 

 

Similar Threads

  1. Shopping cart - trying to turn off "Total Items" "Weight" and "Price"
    By deshojo in forum Templates, Stylesheets, Page Layout
    Replies: 11
    Last Post: 4 Apr 2011, 07:15 PM
  2. Replies: 2
    Last Post: 11 Feb 2010, 09:13 PM
  3. Replies: 3
    Last Post: 3 Jun 2008, 11:41 AM
  4. Replies: 0
    Last Post: 5 Jan 2007, 02:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg