ColdFusion - Creating column names dynamically with CFLOOP

前端 未结 2 781
时光说笑
时光说笑 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:14

    (The original question was already answered. But just to illustrate ...)

    A more flexible structure is to store the documents as rows. So basic table might be:

    TABLE:    tblDocuments
    COLUMNS:  DocumentID  (unique record id)
              UserID
              DocumentName
    

    Using this structure, you could retrieve all existing documents for a single user with a simple query

    
         SELECT documentID, documentName
         FROM   tblDocuments
         WHERE  userID = 
    
    

    .. and display them with a simple output loop. (Note, I added "documentID" as hidden field to identify existing documents ..)

    
       ...
       
       
       (current file name: #documentName#)
    
    

    If the query contains less than 14 files (or whatever your maximum is..), you can use the query.recordCount to determine how many additional file inputs to display.

    
    
    
       
       
    
    
    

提交回复
热议问题