Solved

2 dimensional checkboxes

Posted on 2004-10-26
179 Views
Last Modified: 2010-03-05
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.

0
Question by:haagendaz
    5 Comments
     
    LVL 5

    Accepted Solution

    by:

    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.

    0
     
    LVL 1

    Author Comment

    by:haagendaz
    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.. =)
    0
     
    LVL 5

    Expert Comment

    by:ITcrow

    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;
         }
    0
     
    LVL 1

    Author Comment

    by:haagendaz
    Sorry for late response, i try your way but still have the same error.
    0
     
    LVL 5

    Expert Comment

    by:ITcrow
    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>
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now