Solved

Using cfloop with image upload

Posted on 2006-11-02
4
240 Views
Last Modified: 2010-04-16
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_photos')>
  <!--- Get Photo Number --->
<CFLOOP from="1" to="#form.lastnum#" index="i">
<CFSET countVar=startcount+1>
<cf_autoresize_jrp imagepath="d:\inetpub\expat-online\club\irishclub\images\album\fullsize" maxsize="500" thumbsize="150" prefix="tn_" filefield="photo_#countVar#" thumbpath="d:\inetpub\expat-online\club\irishclub\images\album\thumbnail" 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
0
Comment
Question by:tubize
  • 3
4 Comments
 
LVL 4

Expert Comment

by:hclgroup
ID: 17861216
before the loop
<CFSET #startcount#=0>

within the loop
<CFSET #countVar#=#startcount#+1>
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 17861312
=== ignore last comment ===

before loop
<CFSET #countVar#=0>

inside loop
<CFSET #countVar#=#countVar#+#startcount#+1>
0
 
LVL 4

Accepted Solution

by:
hclgroup earned 125 total points
ID: 17861319
Also, I noticed that startcount wasn't initialised anywhere
0
 

Expert Comment

by:kieken69
ID: 17893645
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\expat-online\club\irishclub\images\album\fullsize" maxsize="500" thumbsize="150" prefix="tn_" filefield="photo_#i#" thumbpath="d:\inetpub\expat-online\club\irishclub\images\album\thumbnail" 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>
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 129
advertisement module in core php 4 160
Java Loop 6 59
Query group by data in SQL Server - cursor? 3 31
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question