Hi expert,
I been doing checkbox options..tick means yes for that particular option for that respective account and insert the value (1) into database. In a row, i have about 5 checkbox and unlimited account contains the values of the options in checkbox form. I have problems in this, i oni able to show and change the value of the options for the first account but unable to do for the others accounts (which show in a same table) in a same time. Can you help me to fix this problem?...i wan checkboxes that able to show value and change the value for all the accounts at a same time in a same button.
Here is my pseudocode:
sub UpdateOnOff{
my @acc_id = $db->select_or({
field=>[qw(acc_id)],
table=> 'account',
});
my %data;
while(my (@acc_id) = $db->fetchrow){
foreach my $acc_id(@acc_id){
my $FwdOpt = $acc_id . '_forward_sms_opt';
my $forward_sms_opt = $q->param($FwdOpt);
my $EmailOpt = $acc_id . '_forward_email_opt';
my $forward_email_opt = $q->param($EmailOpt);
my $Response = $acc_id . '_response_opt';
my $response_opt = $q->param($Response);
my $Textline = $acc_id . '_textline_opt';
my $textline_opt = $q->param($Textline);
my $Bulksms = $acc_id . '_bulksms_opt';
my $bulksms_opt = $q->param($Bulksms);
if ($forward_sms_opt eq 'on'){
my %data = (
forward_sms_opt => 1,
);
$db->db_update('account', \%data, [
['acc_id' => $acc_id],
['forward_sms_opt' => 0],
]);
}
elsif ($forward_sms_opt eq ''){
my %data = (
forward_sms_opt => 0,
);
$db->db_update('account', \%data, [
['acc_id' => $acc_id],
['forward_sms_opt' => 1],
]);
}
:
:
:
$out->redirect("$url_app?m=Admin&c=LstAccount");
}
########htm.tmpl########
.
.
.
[% FOREACH entry = data %]
<tr class=[% loop.count % 2 == 1 ? 'listBG' : 'listBG2' %]>
<td><input type = "checkbox" name = "acc_id" value = "[% entry.acc_id %]"></td>
<td>[% loop.count %].</td>
<td>[% entry.acc_name %]</td>
<td><a href="[% vir_app %]?m=Admin&c=EdtAccount&acc_id=[% entry.acc_id %]">[% entry.comp_name %]</a></td>
<td align=center>[% q.checkbox('-name'=>entry.forward_sms_opt_name, '-checked'=>entry.forward_sms_opt, '-label'=>'') %]
</td>
<td align=center>[% q.checkbox('-name'=>entry.forward_email_opt_name, '-checked'=>entry.forward_email_opt, '-label'=>'') %]</td>
<td align=center>[% q.checkbox('-name'=>entry.response_opt_name, '-checked'=>entry.response_opt, '-label'=>'') %]</td>
<td align=center>[% q.checkbox('-name'=>entry.textline_opt_name, '-checked'=>entry.textline_opt, '-label'=>'') %]</td>
<td align=center>[% q.checkbox('-name'=>entry.bulksms_opt_name, '-checked'=>entry.bulksms_opt, '-label'=>'') %]</td>
<td>[% entry.status %]</td>
</tr>
[% END %]
.
.
.
[% q.submit('-name' => '.UpdateOnOff', '-value'=>'Update Option', '-title'=>'Update selected option(s)') %]
.
.
.
Thank you for your help...and please response as soon possible.
p.s: I will increase the points if anyone able to gif a good solution to me.
by: ITcrowPosted on 2004-10-27 at 01:23:00ID: 12419382
if( contition1) {
my %data = ( .... );
}
elsif( condition2) {
my %data = ( .... );
}
else {
my %data = ( .... );
}
should be replaced with:
my %data;
if( contition1) { $data{ var } = 1;
}
elsif( condition2) { $data{var} = 0;
}
else { $data{var} = 2;
}
Key here is to avoid use of 'my' for the same object/variable in single if-else
BTW, are getting the data of the accounts correctly ?
Try putting a print line in 'foreach' loop to validate the correctness.