Why not make the price input include the product_id...like so (early morning
pseduo-code warning):

<input type="text" name="cost_#product_id#">

Then, on the actionpage, loop through the form like so:

<cfset formarray = listtoArray(form.fieldnames)>
<cfloop from="1" to="#arraylen(formarray)#" index="i">
  <cfif listfirst(formarray[i], 1, "_") IS "cost">
   <cfquery name="update">
   UPDATE yourtable
   SET cost = #form[formarray[i]]#
   WHERE id = #listgetat(formarray[i], 2, "_"#
   </cfquery>
   </cfif>

</cfloop>

On 2/11/06, Michael Grove <[EMAIL PROTECTED]> wrote:
>
> Long story short, I have a page that lists all of the products in our
> database. We are trying to add contract pricing. Basically each product in
> the system may have a different price for each contract.
>
> I have built a form that lists all of the products in the database (around
> 700) with a blank form field (contractprice) next to each row. in the row I
> also include the (product_id, hidden). I would like to be able to add
> pricing the rows and press a single submit button.
>
> What i am not sure about is how to loop through the database to perform,
> INSERT, UPDATE and/or DELETE base on what the form passes.
>
> When the data is passed their are 4 different scenerios (if) that would
> take place.
>
> I am thinking that a call would need to be made to the database for each
> row passed.
>
> 1. if the form.product_id does not and the form.contractprice IS NULL, do
> nothing.
>
> 2. if the form.product_id does not exists and the form.contractprice IS
> NOT NULL, insert the row.
>
> 3. If form.product_id exists but form.contractprice IS NULL, delete row
>
> 4. if form.product_id exists and form.contractprice NOT NULL, update row.
>
> My two major questions is one how would you right the loop to do this and
> two, is there a better way to do this. I do not have access to stored proc
> on the SQL server.
>
> Thanks for the assist...
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:232099
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to