ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

a++ not incrementing

September 20, 2012 12:18am

Subscribe [2]
  • #1 / Sep 20, 2012 12:18am

    TinyBrands

    23 posts

    So, I’m trying to set up a rating system and am trying to do some operations on the number of reviews and ratings. I have the following code:

    {exp:channel:entries channel="businesses" entry_id="{entry_id}” dynamic=“no” limit=“1”}
    {reverse_related_entries entry_id="6"}
    <?php
      $rating = 0;
      $num_reviews = 0;
    ?>

      <?php
      $num_reviews++;
      $rating += floatval(’{rating}’) * 20;
      ?>
    {/reverse_related_entries}
    {/exp:channel:entries}

    the problem (one of many) is that $num_reviews returns 1 1 1 1 1. There are 5 reviews so I am guessing that it is looping 5 times, but each loop starts at value of 0. My desire result is that if it loops 5 times (once for each review), it should increment thusly: 1 2 3 4 5. Any ideas? not sure if I even make sense (much of this is new to me)

  • #2 / Sep 20, 2012 12:43am

    Unless you limit it somehow, everything you put inside a channel:entries loop will be repeated for every entry you’re pulling - it’ll start over every time.

    What sort of output are you looking for? There are built-in {count} variables and others that may help you; you might not need the raw php.

  • #3 / Sep 21, 2012 5:19pm

    Kevin Smith

    4784 posts

    Hi TinyBrands,

    While we can’t provide support for custom development here, I’d be more than happy to move this thread over to the Development and Programming forum so that other third-party developers can provide some help. Would you like me to do that?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases