Reply to topic
I need a tutorial
2onboard


Joined: 30 Apr 2009
Posts: 14
Reply with quote
I need to do the following, but not sure how to get started, advice or a tutorial would be great.

I have a form that I have 12 rows (one for each month)
Next to each month I have a cfinput text box to allow for an amount to be entered for each month

January _____
February _____
March _____
etc.

I want to have one submit button that submits all values
year (set previously in code)
month (as a number 1, 2, 3, etc.)
and the amount entered in the box

so the DB would look something like
ID Rental Year Rental Month Rental Rate
22 2010 1 3000
23 2010 2 3500
24 2010 3 3750
etc

but I'm not sure how to procede??
I can do a cfloop from 1 to 12 index m - to create the form, but I don't know how to name things or tie to them together so that things get entered into the DB properly
cfsearching


Joined: 27 Jul 2008
Posts: 29
Reply with quote
I can do a cfloop from 1 to 12 index m


Just use the loop index "m" to dynamically name the fields: amount1, amount2, ....., amount12. Then on your action page, do another loop to extract and insert the values.

Inside each loop, extract the value of each field with array notation:
Code:

         <cfloop index="m" ..>
                <!--- get the values of each dynamically named field --->
                <cfset variables.amount = form["amount"& m]>

                <!--- Obviously, DO use cfqueryparam here instead ..  --->
                <cfquery ...>
                       INSERT INTO YourTable( YearCol, MonthCol, AmountCol )
                       VALUES ( #form.year#, #m#, #variables.amount# )
                </cfquery>
         </cfloop>


Though I myself would probably use a little of redundancy to make it a bit more dynamic. But you get the idea.
2onboard


Joined: 30 Apr 2009
Posts: 14
Reply with quote
I reallly appreciate the help, but over my head.
Could you supply a more detailed example, or link to tutorial?
2onboard


Joined: 30 Apr 2009
Posts: 14
Reply with quote
wait - wait .... I think I get it...

Thanks for your help
cfsearching


Joined: 27 Jul 2008
Posts: 29
Reply with quote
Good! Let us know if you need more help.
I need a tutorial
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic