Hi
i have a checkbox in my script

<input type="checkbox" name ="pulse[]" value="1" checked>1<br>
                            <input type="checkbox" name ="pulse[]" value="2" checked>2<br>
                            <input type="checkbox" name ="pulse[]" value="3" checked>3<br>
                            <input type="checkbox" name ="pulse[]" value="4" checked>4

and in my program i read the value and i test if the choice was 1 send it to prog1
if it is 2 i send it to prog2 and so...
but i cannot test it if the choice is 1 and 2 or 1 and 3 and so...

`if (isset($_POST['pulse'])){
     //do here some validation of array elements!
      $pulse1 = array();
      foreach($_POST['pulse'] as $p){
        $pulse1[] = $p;
      }
   }
    $ser= implode(' ', $pulse1);
$c=count($pulse1);
     if($c>=4){
        include('full.php');  
        $netw = empty($_POST['netw'])?null:$_POST['netw'];
        $client = empty($_POST['client'])?null:$_POST['client']; 
        getRecords($date,$date2,$report,$client,$netw,$auto);
     }
else{ 
if($ser==1){
    include('daily3.php');  
    dall2($date,$date2,$report,$auto,$ser); 
  }
if($ser==2){
    include('daily32.php');  
    dall32($date,$date2,$report,$auto,$ser);
  }
  .......


    if (isset($_POST['pulse'])){
             //do here some validation of array elements!
              $pulse1 = array();
              foreach($_POST['pulse'] as $p){
                $pulse1[] = $p;
              }
           }
            $ser= implode(' ', $pulse1);
        $c=count($pulse1);
             if($c>=4){
                include('full.php');  
                $netw = empty($_POST['netw'])?null:$_POST['netw'];
                $client = empty($_POST['client'])?null:$_POST['client']; 
                getRecords($date,$date2,$report,$client,$netw,$auto);
             }
        else{ 
        if($ser==1){
            include('daily3.php');  
            dall2($date,$date2,$report,$auto,$ser); 
          }
        if($ser==2){
            include('daily32.php');  
            dall32($date,$date2,$report,$auto,$ser);
          }
Member Avatar for LastMitch

but i cannot test it if the choice is 1 and 2 or 1 and 3 and so...

Did you assigned an valve for each statement so you can see the choice.

For example

if ( $c == 1 ) {
    echo "It's choice 1";
} else {
    echo "It's choice 2";
}

when you select any of those 4 choices and submit it will should tell you what each value does.

There should be only 1 pulse.

Yes, I'm having trouble looking at your code because it's all green.

hi
but if i choose 1 and 2 here is my problem when i choose only 1 and 2 it goes like i choose 1

$ser=array();
if (isset($_POST['pulse'])){
     //do here some validation of array elements!
      $pulse1 = array();
      foreach($_POST['pulse'] as $p){
        $pulse1[] = $p;
      }
   }
    $ser= implode(' ', $pulse1);
$c=count($pulse1);
     if($c>=4){
        include('full.php');  
        $netw = empty($_POST['netw'])?null:$_POST['netw'];
        $client = empty($_POST['client'])?null:$_POST['client']; 
        getRecords($date,$date2,$report,$client,$netw,$auto);
     }
else{ 
if($ser==1){
    include('daily3.php');  
    dall2($date,$date2,$report,$auto,$ser); 
  }
if($ser==2){
    include('daily32.php');  
    dall32($date,$date2,$report,$auto,$ser);
  }
if($ser==3){
    include('daily33.php');  
    dall33($date,$date2,$report,$auto,$ser);
  }
if($ser==4){
    include('daily44.php');  
    dall44($date,$date2,$report,$auto,$ser);
  }
if($ser==1 && $ser==2){
    include('onetwo.php');  
    two($date,$date2,$report,$auto,$ser);
  }

}
?> 
Member Avatar for LastMitch

@asaidi

but if i choose 1 and 2 here is my problem when i choose only 1 and 2 it goes like i choose 1

You can try to used the switch function:

if ($ser == 1) {
    echo "choice 1"; 
} elseif ($ser == 2) {
    echo "choice 2";
} elseif ($ser == 3) {
    echo "choice 3"; 
} elseif ($ser == 4) {
    echo "choice 4";
} elseif ($ser == 5 ? $ser == 1 : $ser == 2) {
    echo "choice 5";
}

switch ($i) {
    case 1:
        echo include('daily3.php');
        dall2($date,$date2,$report,$auto,$ser); 
        break;
    case 2:
        echo include('daily32.php'); 
        dall32($date,$date2,$report,$auto,$ser);
        break;
    case 3:
        echo include('daily33.php'); 
        dall33($date,$date2,$report,$auto,$ser);
        break;
    case 4:
        echo include('daily44.php'); 
        dall44($date,$date2,$report,$auto,$ser);
        break;
    case 5:
        echo include('onetwo.php'); 
        two($date,$date2,$report,$auto,$ser);
        break;
}
Member Avatar for Zagga

Hi asaidi,

You seem to be getting your variable types confused.

On line 1 you initialise $ser as an array.
On line 9 you set $ser as a string.
On line 18 you compare $ser as an integer.

If you just need to know which boxes were checked, it may be easier if you give your form fields separate names:

<input type="checkbox" name ="pulse1" value="doesnt matter">1<br>
<input type="checkbox" name ="pulse2" value="doesnt matter">2<br>
<input type="checkbox" name ="pulse3" value="doesnt matter">3<br>
<input type="checkbox" name ="pulse4" value="doesnt matter">4

Then in the PHP:

$count = 0;
if (isset($_POST['pulse1']))
$count += 3; // A prime number

if (isset($_POST['pulse2']))
$count += 5; // Another prime number

if (isset($_POST['pulse3']))
$count += 7; // Another prime number

if (isset($_POST['pulse4']))
$count += 11; // Another prime number

Depending on the value of $count, you can work out what boxes were checked (because we used prime numbers all values will be unique).
For example:

If $count is 0, no boxes were checked.
If $count is 3, only box 1 was checked.
If $count is 5, only box 2 was checked.
If $count is 7, only box 3 was checked.
If $count is 11, only box 3 was checked.

If $count is 8, boxes 1 and 2 were checked.
If $count is 10, boxes 1 and 3 were checked.
If $count is 14, boxes 1 and 4 were checked.

If $count is 12, boxes 2 and 3 were checked.
If $count is 16, boxes 2 and 4 were checked.

If $count is 18, boxes 3 and 4 were checked.

If $count is 15, boxes 1, 2 and 3 were checked.
If $count is 19, boxes 1, 2 and 4 were checked.
If $count is 21, boxes 1, 3 and 4 were checked.

If $count is 23, boxes 2, 3 and 4 were checked.

If $count is 26, all boxes were checked.

It sounds a lot more complicated than it actually is :)

Hi
i have never used switch ..can i use $ser instead of $i as it is in your example
$count it is 1 when the user checked only 1 case and so
$count it the count of array
thanks

Member Avatar for LastMitch

@asaidi

i have never used switch ..can i use $ser instead of $i as it is in your example

Yeah, you put $ser. instead of $i.

Hi
still i can get worked when i choose 1 and 2

switch ($pulse) {
case 1:
echo include('daily3.php');
dall2($date,$date2,$report,$auto,$ser);
break;
case 2:
echo include('daily32.php');
dall32($date,$date2,$report,$auto,$ser);
break;
case 3:
echo include('daily33.php');
dall33($date,$date2,$report,$auto,$ser);
break;
case 4:
echo include('daily44.php');
dall44($date,$date2,$report,$auto,$ser);
break;
default:
if($pulse[0]==1 && $pulse[1]==2){
echo include('onetwo.php');
two($date,$date2,$report,$auto);
}
break;
}
Member Avatar for LastMitch

@asaidi

still i can get worked when i choose 1 and 2\

What are you talking about?

I mean you are having problems with this:

if($pulse[0]==1 && $pulse[1]==2){
echo include('onetwo.php');
two($date,$date2,$report,$auto);
}
break;

You can't used if statement like that.

This your input:

<input type="checkbox" name ="pulse[]" value="1" checked>1<br>
<input type="checkbox" name ="pulse[]" value="2" checked>2<br>
<input type="checkbox" name ="pulse[]" value="3" checked>3<br>
<input type="checkbox" name ="pulse[]" value="4" checked>4<br>

Where is $pulse[0]==1 && $pulse[1]==2?

onetwo.php is the that you want not daily3.php & daily32.php? Unless you didn't explain it very clearly.

Hi
maybe i did not explain well
if only one checked and it is number 1 the value of the first checked is 1 and 2 for checked 2 and so
when it is 1 then i run the program daily3 for 2 is daily 32 for 3 daily33 and 4 for daily44
but what if the user choose 1 and 2 means the 1 and 2 are checked..

Member Avatar for LastMitch

if only one checked and it is number 1 the value of the first checked is 1 and 2 for checked 2 and so when it is 1 then i run the program daily3 for 2 is daily 32 for 3 daily33 and 4 for daily44 but what if the user choose 1 and 2 means the 1 and 2 are checked..

I don't understand what you are trying to do?

This what I understand so far:

<input type="checkbox" name ="pulse[]" value="1" checked>1<br>
<input type="checkbox" name ="pulse[]" value="2" checked>2<br>
<input type="checkbox" name ="pulse[]" value="3" checked>3<br>
<input type="checkbox" name ="pulse[]" value="4" checked>4<br>

When you check number 1 it should go to daily3.php
When you check number 2 it should go to daily32.php
When you check number 3 it should go to daily33.php
When you check number 4 it should go to daily44.php

yes that is but i check 1 and 2 or 1 and 3 and so...

Member Avatar for LastMitch

yes that is but i check 1 and 2 or 1 and 3 and so...

If you want to combine meaning check 1 and 2 at the same time is totally different what you mention throughout the whole thread.

HI
then it is another way to do it
but why when i print_r the array i can see the 2 values selected or 3 and i cannot test them
print_r($pulse);
1,2

Member Avatar for LastMitch

then it is another way to do it
but why when i print_r the array i can see the 2 values selected or 3 and i cannot test them

I'm very confused right now.

First, you said you can't select the data.

Then you mention that you need to check 2 or 3 checkbox at once.

Now you said you have another way?

Hi
when i select 1 and 2 or 1 and 3 or 2 and 4 etc..
my report prints only 1 value choose
ex:
i have a script prints report when user choose 1 another script prints when a user 2 and so until 4
but when i choose 1 and 2 it prints like i choose 1 and if i choose 2 and 3 it prints like i choose 2 and so..

HI
that what i did and now it is working when i choose 1 and 2

elseif($c==2&&$serv1[0][0]==1&&$serv1[0][1]==2){

  include('onetwo.php');
  two($date,$date2,$report,$auto);
}

thank you very much for your time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.