I have a question regarding coldfusion and loops. I have this program where I ask for user input from the user. The user can enter something for each food item.
<cfloop query = "GET_ITEM">
<tr>
<td align="left" nowrap>
<label>#GET_ITEM.ITEM_NBR#</label>
</td>
<input type="hidden" name="Item_number" id="Item_number"
value="#GET_ITEM.ITEM_NBR#">
<td>
<input type="text" name="on_hand" id="on_hand" value="" size="20"
onKeyPress="javascript:CheckNumeric();" />
</td>
<td>
<input type="text" name="transit" id="transit" value="" size="20"
onKeyPress="javascript:CheckNumeric();" />
</td>
<td>
<input type="text" name="target_level" id="target_level" value=""
size="20" onKeyPress="javascript:CheckNumeric();" />
</td>
<td>
<input type="text" name="percentonhand" id="percentonhand" value=""
size="20" onKeyPress="javascript:CheckNumeric();" />
</td>
</tr>
</cfloop>
I want to insert each record into my table seperately using the below code.
<cfquery name = "insert_records">
<cfloop index="Form.On_hand" list="#FORM.On_hand#" delimiters=",">
Insert into sometable
(VENDORCODE,
ITEM_NBR,
Item_desc,
Target_Level,
Target_Date_Active,
Target_Date_End,
Vendor_name,
Per_of_Actual
)
Values (
<cfqueryparam value = "#Form.Vendor_code#" cfsqltype = "CF_SQL_INTEGER">,
<cfqueryparam value = "#Item_number#" cfsqltype = "CF_SQL_VARCHAR"> ,
<cfqueryparam value = "#Trim(itemdesc.Item_desc)#" cfsqltype = "CF_SQL_VARCHAR">,
<cfqueryparam value = "#Trim(FORM.On_hand)#" cfsqltype = "CF_SQL_INTEGER">,
'2014-12-02',
'2040-01-01',
<cfqueryparam value = "#Trim(itemdesc.Vendor_name)#" cfsqltype = "CF_SQL_VARCHAR">,
100
)
</cfloop>
</cfquery>
My issue is two things.
- How do I ask for the user input and make each record unique?
- After I get the input how do I insert each record seperately into the database.