How to get a dynamic attribute name in cfloop over query in ColdFusion

前端 未结 1 1355
野趣味
野趣味 2021-01-18 08:56

I\'m inside a cfloop over a query. I want to get an attribute, but I won\'t know what that attribute will be until runtime. Using #qryResult[MyAttr]#

1条回答
  •  不要未来只要你来
    2021-01-18 09:42

    
      
      
       Test 1: #qryResult.autoid# 
    Test 2: #qryResult[MyAttr][qryResult.CurrentRow]#

    CurrentRow is implicit in the literal syntax (query.col). It is tied to the index of / (or 1 when used outside a loop).

    Mentioning it explicitly is necessary in the "array index" syntax (query[col][row]), because query[col] alone returns the column object (which is the "complex type" the error refers to).

    Side effect: You can use this for random access to a query result outside of a loop (i.e. as a multi-dimensional array). Once you know the numbers of the rows that interest you, you can access the rows directly.

    0 讨论(0)
提交回复
热议问题