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.

If statement with count?

August 21, 2012 3:35pm

Subscribe [2]
  • #1 / Aug 21, 2012 3:35pm

    Brian_az

    36 posts

    Hello,

    I have a channel buildings and a channel suites, and I use count to automatically show how many suites each buidling has.

    This works great:

    {reverse_related_entries sort="desc" orderby="title"}
                    {if count == total_results}
              Spaces available: {total_results}
                    {/if}
    {/reverse_related_entries}

    This leaves a row blank if there are no available suites. I cant figure out how to add an if statement to show:

    Space available: inquire

    when there are no spaces.

    Any ideas?

  • #2 / Aug 22, 2012 2:56pm

    Rob Allen

    3114 posts

    Not tested but you could try an extra conditional to test for a minimum count of 1:

    {if count >= 1}
    {if count == total_results}
    Spaces available: {total_results}
    {/if}
    {/if}
  • #3 / Aug 22, 2012 4:25pm

    Dan Decker

    7338 posts

    Hey Brian,

    Rob’s code ought to do the trick. Can you confirm?

    Cheers,

  • #4 / Aug 22, 2012 5:24pm

    Brian_az

    36 posts

    In that code where would I put the

    Space available: inquire

    part?

  • #5 / Aug 23, 2012 1:51pm

    Dan Decker

    7338 posts

    Try this:

    {reverse_related_entries sort="desc" orderby="title"}
    {if no_reverse_related_entries}
    Space available: inquire
    {/if}
    {if count >= 1}
    {if count == total_results}
    Spaces available: {total_results}
    {/if}
    {/if} 
    {/reverse_related_entries}

    The new conditional would display your “inquire” message in the event that no result were returned. Presumably, all suites are taken?

    ~

  • #6 / Aug 23, 2012 4:32pm

    Brian_az

    36 posts

    Yep, when all spaces are taken.

    Thanks! That works great!!!

  • #7 / Aug 24, 2012 3:47pm

    Dan Decker

    7338 posts

    Sweet.

    Glad we could help!

    If you need anything else, please let us know.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases