0

I have 3 variable mat , follow , not only one can have value at a time what I want if any of the variables has value it should be updated in msg

this is my logic

<?php     
    $mat = $this->input->post('mater_mesaage') ;
    $folow = $this->input->post('follow_message') ;
    $not = $this->input->post('not_inst_comment') ;     
    if (isset($mat)){
        echo "Mat";
        $msg = $mat  ;
    } 
    if (isset($folow )) {
        echo "folow" ;
       $msg = $folow ;
    }
    if (isset($not)){
        echo "not" ;
        $msg = $not ;
    }
    echo $msg ;
?>
khushmeet singh
  • 106
  • 1
  • 9

3 Answers3

1

please replace == with =

<?php     
    $mat = $this->input->post('mater_mesaage') ;
    $folow = $this->input->post('follow_message') ;
    $not = $this->input->post('not_inst_comment') ;     
    if (isset($mat)){
        echo "Mat" ;
        $msg = $mat  ;
    } 
    if (isset($folow )) {
        echo "folow" ;
        $msg = $folow ;
    }
    if (isset($not)){
        echo "not" ;
        $msg = $not ;
    }
    echo $msg ;
?>
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37
0

One value at a time so u should have to use elseif so here you go:

<?php     
    $mat = $this->input->post('mater_mesaage') ;
    $folow = $this->input->post('follow_message') ;
    $not = $this->input->post('not_inst_comment') ;     
    if (isset($mat)){
        echo "Mat";
        $msg == $mat;
    }elseif (isset($folow )) {
        echo "folow";
       $msg == $folow;
    }else{
        echo "not";
        $msg == $not;
    }
    echo $msg;
?>
Noman
  • 1,459
  • 2
  • 18
  • 38
0
<?php     
    $mat = $this->input->post('mater_mesaage');
    $folow = $this->input->post('follow_message');
    $not = $this->input->post('not_inst_comment');     
    if ($mat != '' || $folow != '' || $not != '') {
        $msg = ($mat != '') ? $mat : (($folow != '') ? $follow : $not);
    }
?>
Noman
  • 1,459
  • 2
  • 18
  • 38
jakub wrona
  • 2,212
  • 17
  • 17
  • the issue here is if $mat has value it will be printed but if $follow or $not has value it is not printing Your code also has the same issue – khushmeet singh Sep 21 '16 at 05:17