Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

2 dimensional checkboxes

Posted on 2004-10-26
8
Medium Priority
?
207 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
Comment
Question by:haagendaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 5

Accepted Solution

by:
ITcrow earned 320 total points
ID: 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.

0
 
LVL 1

Author Comment

by:haagendaz
ID: 12419826
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
ID: 12419908

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
ID: 12450423
Sorry for late response, i try your way but still have the same error.
0
 
LVL 5

Expert Comment

by:ITcrow
ID: 12450721
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

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

610 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