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 null, pk)
document1 (varchar(250), null)
document2 (varchar(250), null)
/* and this continues through */
document14 (varchar(250), null)
So I query for any documents for a particular record:
<cfquery name="qryGetDocs" datasource="#dsn#">
SELECT document1, ...document14
FROM tblDocuments
WHERE documentID = <cfqueryparam name="SESSION.documentID" cfsqltype="cf_sql_integer">
</cfquery>
The form looks something like this:
<form name="frmUploadDocs" method="post" action="documentsPage.cfm">
<input type="file" name="document1" size="50" >
<cfif qryGetDocs.document1 IS NOT ''>
(current file name: <a href="#vars.file_path#/#qryGetDocs.document1#">#qryGetDocs.document1#</a>)</cfif>
<input type="file" name="document2" size="50" >
<cfif qryGetDocs.document2 IS NOT ''>
(current file name: <a href="#vars.file_path#/#qryGetDocs.document2#">#qryGetDocs.document2#</a>)</cfif>
<!--- list all documents --->
<input type="file" name="document14" size="50" >
<cfif qryGetDocs.document14 IS NOT ''>
(current file name: <a href="#vars.file_path#/#qryGetDocs.document14#">#qryGetDocs.document14#</a>)</cfif>
<input type="submit" name="submit" value="Upload Documents">
</form>
I want to loop from 1 to 14, so that I only have one <input>
and <cfif>
statement, like so:
<cfloop from="1" to="14" index="i">
<input type="fiile" name="document#i#" size="30">
<cfif qryGetDocs.document#i# IS NOT ''>
(current file name: <a href="#vars.file_path#/#qryGetDocs.document[#i#]#">#qryGetDocs.document[#i#]#</a>)
</cfif>
</cfloop>
However, I cannot get the syntax correct no matter what I've tried. Can someone please help me with this? Thank you!