Question
cfloop question
I query a table using an orderNumber, and cfoutput my display
in a table, listing partNumber, quantity, and serialNumber.
If the quantity for partNumber PN12345 is 3, then there are three serial numbers for that partNumber. For PN9999, if the quantity is 2, then there are two serial numbers for that part number.
For this example, I would display 5 records for the order number and put a checkbox next to each record, and if checked, delete that record.
This is the code that I use for display and checkbox :
<td valign="top" class="TitleText" align="center">
<cfinput type="checkbox" name="del/#serialNumberID#/#quantity#" value="Yes"></td>
<td valign="top" class="TitleText" align="center">#partNumber#</td>
<td valign="top" class="TitleText" align="center">#quantity#</td>
<td valign="top" class="TitleText" align="center">#serialNumber</td>
If I check one line item to delete for PN12345, that record should be deleted (actually updated to 0) and the quantity should be reduced by 1, since there are only two lines now.
This is the code I am using in my action page :
<cfloop index="i" list="#FORM.FieldNames#" DELIMITERS="," >
<cfif LEFT(i, 4) IS "del/">
<cfset select_serialNumberID = listgetat(i, 2, "/")>
<cfset select_quantity = listlast(i, "/")>
</cfif>
<cfquery name="qryUpdateSerial" datasource="recDisc">
update gfmSerialNumbers
set status = 0
where serialNumberID = '#select_serialNumberID#'
</cfquery>
<cfquery name="qryUpdateQuantity" datasource="recDisc">
update gfmPartNumbers
set quantity = #select_quantity# - 1
from gfmPartNumbers inner join gfmSerialNumbers
on gfmPartNumbers.gfmPartNumberID = gfmSerialNumbers.gfmPartNumberID
where gfmSerialNumbers.serialNumberID = '#select_serialNumberID#'
</cfquery>
</cfloop>
Everything seems to work fine and the quantity is now 2, since one line was deleted.
But here is my problem : If two checkboxes are selected for PN12345, those two lines are deleted and the quantity should be 3 - 2 = 1 (original quantity minus 2 deleted lines). But my query in the loop only is performed once and the quantity is 2 even though both of the selected lines are deleted.
Is my query to delete the quantity in th wrong place ? How do I perform the proper loop to delete the checked lines and get the proper quantity value ?
If the quantity for partNumber PN12345 is 3, then there are three serial numbers for that partNumber. For PN9999, if the quantity is 2, then there are two serial numbers for that part number.
For this example, I would display 5 records for the order number and put a checkbox next to each record, and if checked, delete that record.
This is the code that I use for display and checkbox :
<td valign="top" class="TitleText" align="center">
<cfinput type="checkbox" name="del/#serialNumberID#/#quantity#" value="Yes"></td>
<td valign="top" class="TitleText" align="center">#partNumber#</td>
<td valign="top" class="TitleText" align="center">#quantity#</td>
<td valign="top" class="TitleText" align="center">#serialNumber</td>
If I check one line item to delete for PN12345, that record should be deleted (actually updated to 0) and the quantity should be reduced by 1, since there are only two lines now.
This is the code I am using in my action page :
<cfloop index="i" list="#FORM.FieldNames#" DELIMITERS="," >
<cfif LEFT(i, 4) IS "del/">
<cfset select_serialNumberID = listgetat(i, 2, "/")>
<cfset select_quantity = listlast(i, "/")>
</cfif>
<cfquery name="qryUpdateSerial" datasource="recDisc">
update gfmSerialNumbers
set status = 0
where serialNumberID = '#select_serialNumberID#'
</cfquery>
<cfquery name="qryUpdateQuantity" datasource="recDisc">
update gfmPartNumbers
set quantity = #select_quantity# - 1
from gfmPartNumbers inner join gfmSerialNumbers
on gfmPartNumbers.gfmPartNumberID = gfmSerialNumbers.gfmPartNumberID
where gfmSerialNumbers.serialNumberID = '#select_serialNumberID#'
</cfquery>
</cfloop>
Everything seems to work fine and the quantity is now 2, since one line was deleted.
But here is my problem : If two checkboxes are selected for PN12345, those two lines are deleted and the quantity should be 3 - 2 = 1 (original quantity minus 2 deleted lines). But my query in the loop only is performed once and the quantity is 2 even though both of the selected lines are deleted.
Is my query to delete the quantity in th wrong place ? How do I perform the proper loop to delete the checked lines and get the proper quantity value ?
