Link to home
Start Free TrialLog in
Avatar of haagendaz
haagendaz

asked on

2 dimensional checkboxes

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.

ASKER CERTIFIED SOLUTION
Avatar of ITcrow
ITcrow

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of haagendaz
haagendaz

ASKER

Dear ITcrow,

Thank you for ur response. But im a little confuse...Can u please explain more detail on this :

if( contition1)  { $data{ var } = 1;
}

The var izzit like this one..$forward_sms_opt ? or how ler...if the checkbox tick then it pass value=1 and if not click pass value =0. Then i need to insert the value to the database...From your way how to insert the value to the database?

Oo yeah, i test the getting data, dun have problem. But i cant update the value of the second account, only can update the first account. U clear of my problem now???

Thank you for helping.. =)

It's same as what you had:

     if ($forward_sms_opt eq 'on'){
         
     my %data = (
          forward_sms_opt => 1,
               );

becomes:

     if ($forward_sms_opt eq 'on'){
          $data{ forward_sms_opt } = 1;
     }
Sorry for late response, i try your way but still have the same error.
Could you please post the modified code. It shouldn't be a problem.

A simple sanity check will be good as well.
Usage: perl -cw <script_name>