Coldfusion Select 选项值从数据库中获取项目
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>
我得到了选项标签之间的项目列表,而不是数据库中的项目。
我做错了什么?
我看到你的数组被命名为 Whats
。为什么要尝试从名为 What
的变量中获取值?另外你不正确地调用 item.What_name
.
你应该像你一样循环遍历 Whats
并使用 index
属性,例如。 row
.
<cfloop array="#VARIABLES.Whats#" index="row">
<option VALUE="#row.id#">#row.<thing_you_want_to_display>#</option>
</cfloop>
如果这将在 cfoutput
标签中,这将起作用。
根据评论更新:
改为, only Lucee supports the item
attribute with array loops. For Adobe ColdFusion, use the index
attribute。
<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>
我得到了选项标签之间的项目列表,而不是数据库中的项目。
我做错了什么?
我看到你的数组被命名为 Whats
。为什么要尝试从名为 What
的变量中获取值?另外你不正确地调用 item.What_name
.
你应该像你一样循环遍历 Whats
并使用 index
属性,例如。 row
.
<cfloop array="#VARIABLES.Whats#" index="row">
<option VALUE="#row.id#">#row.<thing_you_want_to_display>#</option>
</cfloop>
如果这将在 cfoutput
标签中,这将起作用。
根据评论更新:
改为item
attribute with array loops. For Adobe ColdFusion, use the index
attribute。