count backwards with cfloop

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default count backwards with cfloop

    hey everyone, i'm trying to list some bits of information by year, starting
    with the current year, and need to do a <cfloop> to do this.

    when i start the list like this: <cfloop from="2005" to="1983" index="i"> it
    doesn't return any records, but when i reverse it and make it: <cfloop
    from="1983" to="2005" index="i"> it works just fine, but puts things in the
    wrong order.

    is there a way have a loop countbackwards?

    my workaround for this is to run the loop from a variable ie:

    <cfset years = '2005,2004,2003'>

    <cfloop list="#years#" index="i">

    is there a better way to do this?

    thanks for your help :)

    ionic77 Guest

  2. Similar Questions and Discussions

    1. CFLoop can't count??
      Hi All, what is wrong with the following code. All it is supposed to do is count the records, take the total number of records list them 1 - 10 in...
    2. Backwards Audio
      At some point I am likely going to be interested in knowing how this happened...but for now, I would just like to resolve it. My audio is recording...
    3. count cfloop query
      How can I display the number of times a query loops? Example: <cfloop query="countthis"> ?? </cfloop> So, if the query produced 10 results,...
    4. SIMPLE Question! - Count <cfloop>
      How can I display the number of times a query loops? Example: <cfloop query="countthis"> ?? </cfloop> So, if the query produced 10 results,...
    5. Backwards Compatibility
      Indeed. What use is an upgrade that criples a program's functionality? This shiould be addressed in an upgrade. CS 1.1 or whatever.
  3. #2

    Default Re: count backwards with cfloop

    Do this:-

    <cfloop from="2005" to="1983" index="i" step="-1">
    Stressed_Simon Guest

  4. #3

    Default Re: count backwards with cfloop

    The default for most loops is usually increment the counter by +1. Try adding step="-1" to the cfloop.
    mxstu Guest

  5. #4

    Default Re: count backwards with cfloop

    thanks for the quick reply! it worked like a charm :)
    ionic77 Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139