我正在尝试在 ColdFusion 中创建一个值列表。基本上,我希望用户能够将他们的乐队成员输入到各个字段中。然后,在提交时,存在的任何值都会作为字符串而不是单个文本值存储到我的数据库中。从数据库中检索它时,运行它并使用逗号作为分隔符并再次单独拆分值。在纸上和我的脑海里,这听起来很简单,但我无法理解它。任何帮助将不胜感激:)
最佳答案
如果您确实想采用该解决方案,您可以简单地使用 listToArray
+cfloop
或仅 cfloop
来获取各个名称:
<CFSET list_names = "John ,Luke, Bob" /> <!--- this should be the value from your db field --->
<CFSET array_names = listtoarray(list_names) />
<CFLOOP array="#array_names#" index="name">
#name# is in the band<br />
</CFLOOP>
或者直接使用列表并循环遍历它:
<CFSET list_names = "John ,Luke, Bob" /> <!--- this should be the value from your db field --->
<CFLOOP list="#list_names#" index="name">
#name# is in the band<br />
</CFLOOP>
但是......我会将乐队成员姓名保存在单独的表中 - 例如:
表波段
:
| id | bandname |
+----+-----------+
| 1 | The Hives |
表bands_members
:
| band_id | name |
+---------+------------------------+
| 1 | Howlin’ Pelle Almqvist |
| 1 | Nicholaus Arson |
| 1 | Vigilante Carlstroem |
关于jquery - 来自 SQL 的 ColdFusion ValueList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14580573/