tubize
asked on
Using cfloop with image upload
I have set up a form to upload up to 9 photos and would like to upload them using cf_autoresize and then add the photo name to my dbase with the sortordr field increasing by one for each photo. I am using the following code:
<cftransaction>
<cfif isdefined('form.submit_pho tos')>
<!--- Get Photo Number --->
<CFLOOP from="1" to="#form.lastnum#" index="i">
<CFSET countVar=startcount+1>
<cf_autoresize_jrp imagepath="d:\inetpub\expa t-online\c lub\irishc lub\images \album\ful lsize" maxsize="500" thumbsize="150" prefix="tn_" filefield="photo_#countVar #" thumbpath="d:\inetpub\expa t-online\c lub\irishc lub\images \album\thu mbnail" nameconflict="makeunique">
<!--- Then post to dbase --->
<cfquery datasource="business" name="InsertData">
Insert into club_albums_photos (photoName, album, sortordr)
values ('#Photo#', #album_no#, #countVar#)
</cfquery>
</cfloop>
</cfif>
</cftransaction>
It keeps uploading the same photo and does not increase thye sortordr by one. This is not a difficult problem but I am at a loss to figure it out.
Thanks
John
<cftransaction>
<cfif isdefined('form.submit_pho
<!--- Get Photo Number --->
<CFLOOP from="1" to="#form.lastnum#" index="i">
<CFSET countVar=startcount+1>
<cf_autoresize_jrp imagepath="d:\inetpub\expa
<!--- Then post to dbase --->
<cfquery datasource="business" name="InsertData">
Insert into club_albums_photos (photoName, album, sortordr)
values ('#Photo#', #album_no#, #countVar#)
</cfquery>
</cfloop>
</cfif>
</cftransaction>
It keeps uploading the same photo and does not increase thye sortordr by one. This is not a difficult problem but I am at a loss to figure it out.
Thanks
John
=== ignore last comment ===
before loop
<CFSET #countVar#=0>
inside loop
<CFSET #countVar#=#countVar#+#sta rtcount#+1 >
before loop
<CFSET #countVar#=0>
inside loop
<CFSET #countVar#=#countVar#+#sta
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hclgroup should be right.
This should work too:
Use the index (=i) of the cfloop and don't use <CFSET countVar...:
<CFLOOP from="1" to="#form.lastnum#" index="i">
<cf_autoresize_jrp imagepath="d:\inetpub\expa t-online\c lub\irishc lub\images \album\ful lsize" maxsize="500" thumbsize="150" prefix="tn_" filefield="photo_#i#" thumbpath="d:\inetpub\expa t-online\c lub\irishc lub\images \album\thu mbnail" nameconflict="makeunique">
<!--- Then post to dbase --->
<cfquery datasource="business" name="InsertData">
Insert into club_albums_photos (photoName, album, sortordr)
values ('#Photo#', #album_no#, #i#)
</cfquery>
</cfloop>
</cfif>
</cftransaction>
This should work too:
Use the index (=i) of the cfloop and don't use <CFSET countVar...:
<CFLOOP from="1" to="#form.lastnum#" index="i">
<cf_autoresize_jrp imagepath="d:\inetpub\expa
<!--- Then post to dbase --->
<cfquery datasource="business" name="InsertData">
Insert into club_albums_photos (photoName, album, sortordr)
values ('#Photo#', #album_no#, #i#)
</cfquery>
</cfloop>
</cfif>
</cftransaction>
<CFSET #startcount#=0>
within the loop
<CFSET #countVar#=#startcount#+1>