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.

Looking up the total amount of entries entered by a user during a specific period of time.

May 16, 2012 2:51pm

Subscribe [2]
  • #1 / May 16, 2012 2:51pm

    the_konstantine

    7 posts

    Hello everyone,
    I’m building a gambling application where channel entries are used as tokens to enter contests. In order to enforce that “3 times per week only” restriction, i’ve tried using the following:

    {exp:channel:entries channel="registrations" dynamic="off" author_id="CURRENT_USER" start_on="<?php echo $paramStart; ?>" stop_before="<?php echo $paramStop; ?>"}
    {if total_results > 2}
    Disallow entering.
    {if:else}
    Allow to enter.
    {/if}
    {/exp:channel:entries}

    However, the {total_results} returns me ‘1’ as its value no matter how many entries have i really made. As you can see there is not limit in the loop so i don’t quite understand why i am having this problem, unless {total_results} is a boolean variable and is simply returning “true” in the value of ‘1’...
    Any ideas or recommendation would be greatly appreciated!

  • #2 / May 16, 2012 9:46pm

    Bhashkar Yadav

    727 posts

    are you getting correct number while not putting {total_results} in if condition?

  • #3 / May 17, 2012 6:53am

    John St-Amand

    865 posts

    You might also need to try {if total_results > "2"} rather than {if total_results > 2}.  I find EE a bit finicky when it comes to conditionals with value comparisons without the quotes around that which is to be compared against (unless it too is a variable).

  • #4 / May 17, 2012 1:41pm

    the_konstantine

    7 posts

    Ok, so it seems like the {total_results} was displaying incorrectly due to a bunch of loops stacking on top of each other…
    Also, it seems like John is right about the reasons it wasn’t acting as expected, the quotes really seem to have helped.
    I’m having just a slight problem left.
    Here is my final code:

    <?php
      $test = "1";
    ?>
    
    {exp:channel:entries channel="registrations" dynamic="off" author_id="CURRENT_USER" start_on="<?php echo $paramStart; ?>" stop_before="<?php echo $paramStop; ?>"}
    
    <!--THIS RIGHT HERE IS JUST TO PRINT THE RESULT OF TESTING PURPOSES AND IT RETURNS THE CORRECT NUMBER OF ENTRIES-->
      The total number of results is: {total_results}
      
    
    <!--END-->
    
      {if total_results > "2"}
      
    <!--SO HERE I AM TRYING TO CHANGE THE VALUE OF THE VARIABLE CREATED BEFORE THE LOOP TO '0'-->
        <?php
          $test = "0";
        ?>
    <!--END-->
        
        First loop works
        
    
     
      {/if}
      {if total_results <= "2"}
    
    <!--AND HERE I AM TRYING TO CHANGE THE VALUE OF THE VARIABLE CREATED BEFORE THE LOOP TO '1'-->   
        <?php
          $test = "1";
        ?>
    <!---->
        
      Second loop works
      
    
        
      {/if}
    
    {/exp:channel:entries}
    
    <!--SO THE LOOP ENDS AND NOW DEPENDING ON HOW THE $TEST VARIABLE HAS BEEN CHANGED THE SYSTEM IS TO DISPLAY ONE OF THE TWO OPTIONS-->
    
    <!--THIS FOR SOME REASON DOESN'T GET CHANGED TO '0' AND CONTINUES BEING ONE EVEN THOUGH IT ENTERS THE FIRST IF STATEMENT IN THE LOOP ABOVE-->
    <?php echo $test; ?>
    <!---->
    
    {if <?php echo $test; ?> == "0"}
        <div>
          Sorry, you've already entered more than 3 times this week
        </div>
    {if:else}
      <div>
          You are about to enter to win tickets for {event_title}. You can enter once a week, don't forget to try again next week!
      </div>
    {/if}

    So my problem now is that for some reason my $test variable isn’t being changed within the loop, which in turn affects what option is displayed after the loop.

    P.S. oh and thanks for help guys, i really appreciate it 😊

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

ExpressionEngine News!

#eecms, #events, #releases