CFLoop can't count??

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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 a
    dropdown box. But I am getting everything but that.

    <cfform action="" method="post">
    <cfloop index="i" from="2" to="#workFlow.recordCount#" step="1">
    <cfoutput>
    <cfselect name="sequence#i#" query="workFlow" display="ID" value="ID">
    <option value=""></option>
    <option value="#i#">#i#</option>
    </cfselect>
    </cfoutput><br />
    </cfloop>
    </cfform>

    Thanks in advance.

    Maurice

    EdmondsM Guest

  2. Similar Questions and Discussions

    1. cfloop
      The goal is to insert a record into table 'atd', which contains a document id and an associate id, for each document (38) and associate (150). So...
    2. Cfloop..
      I am trying to loop over a list: <cfquery name="updsyllabus" datasource="#arguments.syl.dsn#"> UPDATE #arguments.syl.tname# SET <cfloop...
    3. 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...
    4. 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,...
    5. 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,...
  3. #2

    Default Re: CFLoop can't count??

    Move the <cfselect> tag outside of the <cfloop>
    tkrussel Guest

  4. #3

    Default Re: CFLoop can't count??

    With this code, you should be getting #workFlow.recordCount#-1 select boxes.

    What do you want to display? Just the numbers? The content of the query?
    One select box? n select boxes? What do you mean by "anything but"? Can you
    provide a sample of the output, and a sample of how you want it to look?



    philh Guest

  5. #4

    Default Re: CFLoop can't count??

    Hey Phil, there are a total of 15 records in the db. I am using a loop becasue
    if a record gets deleted I don't won't my dropdowns to be number like 123568.
    So using a cfloop will give me the total number of records. Then in each
    dropdown, I want to display 1 - 15 (or whatever the total is) but behind the
    sense, each number has it's own ID. Each ID has a name associated with it.
    That name is going to be displayed next to each select box as a description for
    the select box. Make sense??

    EdmondsM Guest

  6. #5

    Default Re: CFLoop can't count??

    tkrussel, the cfslect has to be in the cfloop becasuse I need a select box for each record in the db.
    EdmondsM Guest

  7. #6

    Default Re: CFLoop can't count??

    Phil, the purpose ofr the numbered dropdowns is so the user can put them in order, from 1 to whatever the total number if items there are in the db.
    EdmondsM Guest

  8. #7

    Default Re: CFLoop can't count??

    It is hard to understand what you're looking for. If you want one select box
    with your records listed, do this:

    <cfselect name="records">
    <cfloop from ="1" to="#arraylen(myRecordsArray)#" index="i">
    <option value="#myRecordsArray[1]#">#myRecordsArray[2]#</option>
    </cfloop>
    </cfselect>

    If you're displaying one of these for each of your items listed form the
    database, include the above code in another cfloop like this:

    <cfloop from ="1" to="#arraylen(myRecordsArray)#" index="m">
    Record Number <cfoutput>#m#</cfoutput>:
    <cfselect name="records">
    <cfloop from ="1" to="#arraylen(myRecordsArray)#" index="i">
    <option value="#myRecordsArray[m][1]#"
    <cfif i EQ m>selected</cfif>>#myRecordsArray[m][2]#</option>
    </cfloop>
    </cfselect>

    </cfloop>


    Syncopation Guest

  9. #8

    Default Re: CFLoop can't count??

    So you want the user to be able to "rank" or order the importance of the
    records? How are you going to relate the choice back to the record? You
    shouldn't depend on the natural order of the record in the table. You're going
    to have to have some way to associate the user's choice with the specific
    record they're ranking, and that is usually done with the primary key.

    So, if you have a primary key, it should be included in the name of the
    CFSELECT object, so you can more easily associate the chosen value with the
    record it's intended for.

    <cfform action="" method="post">
    <cfoutput query="workFlow">


    <cfselect name="sequence#primarykeyfieldvalue#" query="workFlow" display="ID"
    value="ID">
    <option value=""></option>
    <cfloop index="i" from="2" to="#workFlow.recordCount#" step="1">
    <option value="#i#">#i#</option>
    </cfloop>
    </cfselect>

    </cfoutput>
    </cfform>

    HTH,


    philh Guest

  10. #9

    Default Re: CFLoop can't count??

    Hi Phil, your solutions worked with a few tweeks.

    Thanks for your help.
    EdmondsM 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