Hi All,

Here is a piece of code that use to to multi-update via checkboxes, I figure
someone might be able to use it. I got my inspiration from webtricks.com,
awesome site by the way.

<!--- Query your table to get the data you want to update --->
<cfquery name="getData" datasource="YourDSN">
   Select ID FirstName,LastName,EmailAddress From
   Contacts
</cfquery>
<!--- Set a hidden form variable and populate it the recordcount of your
recordset --->

<form action="YourActionPage.cfm" method="Post">
   <table>
       <tr>
       <!--- Populate the recordcount, this allows us to loop to the
recordset later --->
           <td><input type="hidden" name="NumRecords"
value="<cfoutput>#getData.RecordCount#</cfoutput>"></td>
           <td>First Name</td>
           <td>Last Name</td>
           <td>Email</td>
       </tr>
       <!--- Query thru the recordset and populate each row respectively,
notice I created each check box with it's own name, and I use CurrentRow to
name them, IE checkbox1, checkbox2 etc. --->
       <!-- You must add a unique identifier to each field name, do so by
adding the currentrow number to each field name -->
       <cfoutput query="getData">
       <tr>
           <td><input type="checkbox" value="#id#"
name="checkbox#CurrentRow#"></td>
           <td><input name="FirstName#CurrentRow#"
value="#FirstName#"></td>
           <td><input name="LastName#CurrentRow#" value="#LastName#"></td>
           <td><input name="EmailAddess#CurrentRow#"
value="#EmailAddess#"></td>
       </tr>
       </cfoutput>
       <tr>
           <td colspan="4">
               <input type="submit" name="Submit" value="Submit">
           </td>
       </tr>
   </table>
</form>

<!--- YourActionPage.cfm --->
<!--- Loop thru the recordcount to initalize all the checkboxes, why do we
need to do this? because with checkbox unless you check it, it's not going
to be in the form scope --->
<!--- So we init all the checkboxes and gave it default value of empty
string, this will make sure even though we did not check a particular
checkbox it can still be passed to our processing page--->
<cfloop from="1" to="#NumRecords#" index="i">
   <cfparam name="form.checkbox#i#" default="">
</cfloop>

<cfloop from="1" to="#NumRecords#" index="i">
<!--- So now we loop thru all the checkboxes and only process those
checkboxes that have a value --->
   <cfif StructKeyExists(form, "checkbox#i#") AND len(Evaluate("checkbox" &
i))>
       <cfquery datasource="#application.dsn#">
         UPDATE contacts
       SET FirstName = <cfqueryparam value="#Evaluate("FirstName" & i)#"
cfsqltype="CF_SQL_VARCHAR">
       LastName = <cfqueryparam value="#Evaluate("LastName" & i)#"
cfsqltype="CF_SQL_VARCHAR">
         EmailAddress = <cfqueryparam value="#Evaluate("EmailAddress" &
i)#" cfsqltype="CF_SQL_VARCHAR">
         WHERE ID = <cfqueryparam value="#Evaluate("checkbox" & i)#"
cfsqltype="CF_SQL_INTERGER">
       </cfquery>
   </cfif>
</cfloop>
_______________________________________________
Reply to DFWCFUG: 
  [email protected]
Subscribe/Unsubscribe: 
  http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives: 
    http://www.mail-archive.com/list%40list.dfwcfug.org/             
  http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors: 
  www.instantspot.com/
  www.teksystems.com/

Reply via email to