制作数组:
<cfset tempArr = DeserializeJSON(URL.data) />
<cfset temp1 = "" />
<cfset temp2 = "" />
<cfset selectList1 = "" />
<cfset selectList2 = "" />
<cfloop array=#tempArr# index="i">
<cfset temp1 = GetToken(i,1,":")>
<cfset temp2 = GetToken(i,2,":")>
<cfset selectList1 = listAppend(selectList1, temp1)>
<cfset selectList2 = listAppend(selectList2, temp2)>
</cfloop>
循环遍历它??:
<cfquery name="sample" datasource="database">
SELECT *
FROM table
WHERE
<cfloop from="1" to="#listLen(selectList1)#" index="i"/>
#ListGetAt(selectList1, i)# = <cfqueryparam value="#ListGetAt(selectList2)#" />
</cfloop>
<cfif i neq listLen(#selectList1#)>
AND
</cfif>
</cfquery>
我的意图是根据从 javascript 页面接收到的数组在表中动态搜索。数据来自于此form -> columnName:searchBy
。即,样片将是name:Jim
. 我想构建动态代码,允许我按不同的列进行搜索,但我无法让我的循环工作。如果有帮助,我会收到此错误:
(Invalid CFML construct found on line 20 at column 59.)
这是这一行:
<cfloop from="1" to="#listLen(selectList1)#" index="i" />