Search code examples
arrayscoldfusioncfloop

Coldfusion Select Option Value Get Items From Database


        <form action="blog.Logboek" method="post" name="Update_what">
           <select size="1" name="Whats">
               <option>Select an item</option>
                <cfloop array="#VARIABLES.Whats#" item="What_name">
               <option VALUE="#What.id#">#item.What_name#</option>
                </cfloop>
           </select>
           <input type="submit" value="Update_what">
       </form>

I get a list of items with what is between the option tag and not the items from the database.

What am I doing wrong?


Solution

  • As I see your array is named Whats. Why are you trying to get the value from a variable named What? Also you are improperly calling item.What_name.

    You should loop through Whats like you do and use the index attribute eg. row.

    <cfloop array="#VARIABLES.Whats#" index="row">
        <option VALUE="#row.id#">#row.<thing_you_want_to_display>#</option>
    </cfloop>
    

    This will work if this will be in cfoutput tag.

    Update from comments:

    As noted in the comments, only Lucee supports the item attribute with array loops. For Adobe ColdFusion, use the index attribute instead.