Inserting a query loop into the database.
<cfquery datasource="#request.dsn#" name="getStatic">
SELECT Aircraft.SerialNumber As SerialNumber, AircraftType.AircraftType As Type, DocumentTitle, DocumentPath, DocumentID
FROM Aircraft
JOIN AircraftType ON AircraftType.AircraftTypeID = Aircraft.AircraftTypeID
JOIN StaticDocument ON StaticDocument.AircraftTypeID = AircraftType.AircraftTypeID
WHERE Aircraft.SerialNumber = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#URL.ID#">
</cfquery>
<cfloop query="getStatic">
<cfquery datasource="#request.dsn#" name="getPerm">
SELECT AircraftSerialNumber, DocumentID
FROM StaticDocumentSuppress
WHERE AircraftSerialNumber = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#URL.ID#">
AND DocumentID = <cfqueryparam cfsqltype="CF_SQL_INT" value="#DocumentID#">
</cfquery>
<tr>
<td style="padding-left:10px;"><a href="Attachments/Static/#DocumentPath#" target="_blank">#DocumentTitle#</a></td>
<td style="padding-right:10px;" align="right">
<cfinput type="hidden" name="ugh" value="#DocumentID#">
<cfif getPerm.DocumentID EQ "#DocumentID#"><cfinput type="Checkbox" name="DocumentID" value="No" checked="No"><cfelse><cfinput type="Checkbox" name="DocumentID" value="Yes" checked="Yes"></cfif>
</td>
</tr>
</cfloop>
So basically I have a loop query that grabs Documents name and Path from the database. Also in the database there is a permissions table. If your document ID and Aircraft ID is in the row of that table then the document won't be visiable on the frontend. (This is the backend code.) So the user will disselect which document they dont won't. When the checkbox is unselected it is suppose to add a row to the "StaticDocumentSuppress" table with the ID of the document and Aircraft the user does not want to show.
Here is the action code I wrote:
<cfif isDefined("form.btn_add")>
<cfloop list="#form.ugh#" index="i">
<cfif form.DocumentID EQ "No">
<cfquery name="AddPermissionsDB" datasource="#request.dsn#">
INSERT INTO StaticDocumentSuppress
(AircraftSerialNumber,DocumentID)
VALUES
('#url.id#','#i#')
</cfquery>
</cfif>
<cfif form.DocumentID EQ "Yes">
<cfquery name="AddPermissionsDB" datasource="#request.dsn#">
DELETE FROM StaticDocumentSuppress
WHERE AircraftSerialNumber = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#URL.ID#">
AND DocumentID = <cfqueryparam cfsqltype="CF_SQL_INT" value="#i#">
</cfquery>
</cfif>
</cfloop>
This isn't working for me... It only works if you unclick all of the checkboxes or none of them. Single unchecks does not work... What am I doing wrong?
I'm on Coldfusion 8 BTW
