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.

Simple Question - How to get entry No. + 1

September 16, 2012 9:47pm

Subscribe [2]
  • #1 / Sep 16, 2012 9:47pm

    Sunnyland

    66 posts

    It might sound stupidly simple, but I am just wondering how I can take a number from an entry and then + 1 to that number.

    i.e. I have the entry number on the left (21 for example) Then I want to call that entry number again, but present the next incremental integer (22).

    Can anyone suggest how this simple algorithm should be accomplished?

     

  • #2 / Sep 17, 2012 5:32am

    Sunnyland

    66 posts

    I figured out that you can turn on php, and use php slabs within your templates, and figured out how to use operators on integers like a {count} result to get the +1 to the number of entries….

    But I’ve struggled to be able to isolate the final entry and still use the count result to give the number I needed (since I can’t rely on entry_ids as there will be a lot of entries all over), and this number will quickly become useless.

    After trying a bunch of silly javascript and jqery reliant methods, I figured out that you can also use the following to filter by count results:

    {if count == total_results} entry data {/if}

    So In the following manner, I filter out any entry that isn’t the last entry, after calling it to get the number of entries in the channel which match the parameters (this is in order to ONLY get the last number, not a list of numbers for each entry in the channel) and then I use a good old + 1 to get the number I need.

    <div class="item_number">
               {exp:channel:entries channel="trades" sort="desc"}          
                {if count == total_results} <?php echo( {count} +1 ); ?> {/if} 
               {/exp:channel:entries}
              </div>

    voila… so simple, right o,O !!

    LOL I’m sure there’s a better and more elegant / sensible way to do this, but I hope it’s helpful to someone, nonetheless 😊

     

     

  • #3 / Sep 17, 2012 9:21pm

    Sunnyland

    66 posts

    While the above works exactly as expected…

    I guess I am still wondering, is there a better way to collect the entry number in a particular channel, and is there a better way to do native number algorithms in expression engine?

    If not, I’m happy to accept the above method, as this works for now, and might be necessary later anyway since I may have to filter results by users using the same channel, which would confuse number based results in the same way as the entry_id parameter.

    In any case, thanks for looking.

  • #4 / Sep 17, 2012 10:22pm

    MadWebDesigns

    147 posts

    If you don’t want to use PHP you can have a look at this add-on:

    http://devot-ee.com/add-ons/mx-calculator

    Mike

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

ExpressionEngine News!

#eecms, #events, #releases