ColdFusion - Creating column names dynamically with CFLOOP

前端 未结 2 778
时光说笑
时光说笑 2021-01-22 02:45

I have a table that records the name of uploaded documents, up to 14 per record. The columns are named thus:

TABLE tblDocuments
COLUMNS documentID (int, not nu         


        
2条回答
  •  清酒与你
    2021-01-22 03:20

    Queries can be accessed (like structs) with a string index and square brackets, but only if you also include the desired row number (!). This works like a two-dimenisonal array.

    
       
       
         (current file name: #HTMLEditFormat(qryGetDocs["document#i#"][qryGetDocs.CurrentRow])#)
       
    
    

    Note the HTMLEditFormat() to protect yourself against cross site scripting attacks. This is important! Never ever output data to HTML without properly escaping it. (I admit that filenames are an improbable attack vector because they usually cannot contain pointy brackets, but a) you can't be too cautious, b) it's a good habit to get into, and c) no one knows what security holes will pop up when the code gets re-factored at some point in the future. Not HTML-escaping data is inexcusable sloppiness.)

    A more idiomatic and much more readable version would be:

    
       
       
        
       
       
       
         (current file name: #HTMLEditFormat(DocName)#)
       
    
    

提交回复
热议问题