g118481
asked on
Edit multiple rows at one time?
Experts,
I want to be able to edit multiple rows at one time.
I have a Select query that outputs the list of records from a DB table, and I would like to be able to change some values of each record that is displayed, all at one time.
In other words, I want to display the records, then change each records in the list, then click submit and update the table with all my edits. I am using CF 5.0
Is this possible?
If so, can you supply a simple example for me?
Thanks
I want to be able to edit multiple rows at one time.
I have a Select query that outputs the list of records from a DB table, and I would like to be able to change some values of each record that is displayed, all at one time.
In other words, I want to display the records, then change each records in the list, then click submit and update the table with all my edits. I am using CF 5.0
Is this possible?
If so, can you supply a simple example for me?
Thanks
ASKER
I like your example.
However I have a couple of questions:
1. How can I submit the first part of your example?
2. Where in relationship to your part 1 example do I place the form tags, or does it matter?
However I have a couple of questions:
1. How can I submit the first part of your example?
2. Where in relationship to your part 1 example do I place the form tags, or does it matter?
ASKER
I get this error when I run your example.
Should "& kk" be something else?
************************** ********** *****
Error Occurred While Processing Request
Error Diagnostic Information
An error occurred while evaluating the expression:
variables.id = form['id' & kk]
************************** ********** *****
Should "& kk" be something else?
**************************
Error Occurred While Processing Request
Error Diagnostic Information
An error occurred while evaluating the expression:
variables.id = form['id' & kk]
**************************
sorry, I used ii in the CFLOOP and kk in the lines :)
In the CFLOOP switch to kk : index="kk"
In the CFLOOP switch to kk : index="kk"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am not getting the update to write to the table.
It is as if it is by passing the update.
I am not getting any errors, though.
I am working with just one record to try and get this working.
Here is my URL string, which is passing the variables needed.
I have attached the action/update code snippet for review, below.
http://myserver.com:8080/test_update_action.cfm?id1=2713&inPace1=YY&totalRecords=1&initedit_OK=Update
It is as if it is by passing the update.
I am not getting any errors, though.
I am working with just one record to try and get this working.
Here is my URL string, which is passing the variables needed.
I have attached the action/update code snippet for review, below.
http://myserver.com:8080/test_update_action.cfm?id1=2713&inPace1=YY&totalRecords=1&initedit_OK=Update
<cfset dsn = "mydsn">
<cfif isDefined("form.totalRecords")>
<cftry>
<!---- loop through every record, add or update depending on whether they already had an ID ----->
<cfloop index="kk" from="1" to="#val(totalRecords)#">
<cfset variables.somethingEntered = true> <!---- assume some data was entered for each record ---->
<cfset form.id = form['id' & kk]>
<cfset form.inPace = form['inPace' & kk]>
<cfif id eq 0> <!---- no primary key, so insert ---->
<cfif variables.somethingEntered>
no primary key, so insert
</cfif>
<cfelse> <!----- already exists, so update it ----->
<cfif variables.somethingEntered>
<cfquery name="updatePhotos" datasource="#dsn#">
update mytable
set inPace = '#form.inPace#'
where id = #form.id#
</cfquery>
<cfelse>
nothing entered, so delete the record
</cfif>
</cfif>
</cfloop>
<cfcatch type="Any">
<cfset variables.error = cfcatch.message>
</cfcatch>
</cftry>
</cfif>
One tip, for now, add <CFRETHROW> to your CFCATCH to ensure you can see the full error and be sure any errors are not hidden...
<cfcatch type="Any">
<cfset variables.error = cfcatch.message>
<cfrethrow>
</cfcatch>
Just in case you have a variable scoped ID, I would add the form scope to this, along with a val() in case the value is empty instead of zero (i would think it would be empty if no ID)
<cfif id eq 0>
to
<cfif val(form.id) eq 0>
Otherwise, I may have to see the form part of the code..
<cfcatch type="Any">
<cfset variables.error = cfcatch.message>
<cfrethrow>
</cfcatch>
Just in case you have a variable scoped ID, I would add the form scope to this, along with a val() in case the value is empty instead of zero (i would think it would be empty if no ID)
<cfif id eq 0>
to
<cfif val(form.id) eq 0>
Otherwise, I may have to see the form part of the code..
ASKER
Ok, I was able to get it working.
Thank you very much for your time and efforts!
Thank you very much for your time and efforts!
ASKER
Ok, I was able to get it working.
Thank you very much for your time and efforts!
Thank you very much for your time and efforts!
number will associate fields of the same record.
Also create a hidden field to hold the total number of records
(this isn't required but is helpful).
Here's a simple example:
Open in new window