[ic] possible to update multiple records with a single form

Bill Carr bill at bottlenose-wine.com
Thu Jan 22 16:33:52 UTC 2009

On Jan 22, 2009, at 11:11 AM, DB wrote:

>>> I added a field named 'notes' to my orderline table. I want to
>>> create a
>>> form which list the code and notes fields for each orderline record
>>> with
>>> a given order_number, which I can easily to with a mysql query.
>>> But, I want the notes field to be editable for each record and then
>>> have
>>> all records updated when I submit the form.
>>> Does anyone have any experience or advice?
>> I've just done something similar using script.aculo.us inplace  
>> editor.
>> It's not quite exactly what your asking for but the end user
>> experience is similar. If you're interested in that approach I'll  
>> post
>> details.
>> Bill Carr
>> Bottlenose - Wine & Spirits eBusiness Specialists
>> (413) 584-0400
>> http://www.bottlenose-wine.com
> Sure - I'd like to see all possibilities. Thanks!
First of all get http://script.aculo.us/ installed.

Make your page and add something like this:

	your query tag stuff
	make sure you select orderline_id and note
		<div id="orderline_id_[sql-param orderline_id]">[sql-param note]</div>
		<script type="text/javascript" charset="utf-8">
			var opt = { callback: function(form,value) { return  
param orderline_id]&note=' + escape(value)} };
			new Ajax.InPlaceEditor('orderline_id_[sql-param  
orderline_id]','[process]', opt);

The above is untested. I just modified my stuff to hopefully fit your  

I did not use the IC 'process' page in my application. I made a new  
page that I'll post below. You need the page called that does the  
update to return the value updated. There might be a way to do that  
within Interchange but I didn't know it. Update the page below to get  
your Database handle. I do it in a way that is specific to our setup.

[tag op=header]Content-Type: text/html; charset=utf-8;[/tag]
[perl global=1]
	# $Id$
	use feature 'switch';
	given ($CGI->{mv_data_function}) {
		when ('insert') {
			my $values = &get_values($CGI->{mv_data_fields});
			my $sql = qq{INSERT $CGI->{mv_data_table} ($CGI->{mv_data_fields})  
			$sql .= join '","', @$values;
			$sql .= q{")};
			$dbh->do($sql) || return 'Error';
			return $values->[0];
		when ('update') {
			my $return_value;
			my $sql = qq{UPDATE $CGI->{mv_data_table} SET };
			for (split ',', $CGI->{mv_data_fields}) {
				$return_value ||= $CGI->{$_};
				$sql .= qq{$_="$CGI->{$_}", };
			$sql =~ s/, $//;
			$sql .= qq{ WHERE $CGI->{mv_data_key}=$CGI->{$CGI->{mv_data_key}}};
			$dbh->do($sql) || return 'Error';
			return $return_value;
		when ('delete') {
			my $sql = qq{DELETE FROM $CGI->{mv_data_table} WHERE $CGI- 
		when ('sort') {
			my $i = 0;
			for (@{$CGI_array->{$CGI->{sortable_key}}}) {
				my $sql = qq{UPDATE $CGI->{mv_data_table} SET $CGI- 
 >{mv_data_sort_field}=$i WHERE $CGI->{mv_data_key}=$_};
		when ('select') {
			my $sql = qq{SELECT $CGI->{mv_data_fields} FROM $CGI- 
 >{mv_data_table} WHERE $CGI->{mv_data_key}=$CGI->{$CGI- 
			return $dbh->selectrow_array($sql);
	sub get_values {
		my $fields = shift;
		my $data;
		for (split ',', $fields) {
			push @$data, $CGI->{$_};
		return $data;

Good luck.

Bill Carr
Bottlenose - Wine & Spirits eBusiness Specialists
(413) 584-0400

More information about the interchange-users mailing list