0

if condition 1 :

if(isset($_POST['searchOrder']) && $_POST['searchOrder']!='')
   {
       $userToSearch = "WHERE name='Conformed'"; 

   }

If condition 2 :

if(strstr($status, "value1") !== false ) 

    {
    $hide .= 'style="display: none;"';
    }

i need if condition 1 OR If condition 2 , i tried below :

if (((strstr($status, "value1") !== false) ||  
   isset($_POST['searchOrder']) && $_POST['searchOrder']!='')
   {
       $userToSearch = "WHERE name='Conformed'";        
   })
                  {
                     $hide .= 'style="display: none;"';              
                  }

I also tried below , but both gave error....

if ((strstr($status, "value1") !== false) ||  isset($_POST['searchOrder']) && $_POST['searchOrder']!=''))
                  {
                     $userToSearch = "WHERE name='Conformed'";   
                     $hide .= 'style="display: none;"';              
                  }
  • so you want both conditions should be passed ? or any one ? – prakash tank Feb 20 '18 at 13:48
  • @prakashtank i want 1st if condition result and 2nd if condition result in `one if condition`..... –  Feb 20 '18 at 13:49
  • for first one use `!empty($_POST['searchOrder'])` instead of `isset` and `!=""` – AbraCadaver Feb 20 '18 at 13:51
  • @vickey : please check my answer if you want to combine both condition – prakash tank Feb 20 '18 at 13:51
  • It's not clear, you want this : `if ( (condition1) || (condition2) ) {result 1; result 2;}` ? – Mickaël Leger Feb 20 '18 at 13:53
  • @MickaelLeger you are right.... –  Feb 20 '18 at 13:56
  • And it doesn't works if you write it as I do (with the parenthesis around each condition)? And you can write `if (!empty($_POST['searchOrder'])` for your condition 1, empty test if isset + not empty (so not null, not "", etc. Look some doc :) – Mickaël Leger Feb 20 '18 at 14:00
  • @MickaelLeger okay, thanks , i will try , please post an answer with code.... –  Feb 20 '18 at 14:04
  • You already have a lot of anwser :) But I don't get the logic of you code because if you want `if ( (condition1) || (condition2) ) {result 1; result 2;}` you can have `$userToSearch = "WHERE name='Conformed'";` even with `empty($_POST['searchOrder']` because it's a "OR" condition. Maybe you want `condition1 && condition2`, no? But you will have the two result ONLY if BOTH are respected. If the result1 and result2 depend of ONE condition each, why do you want to make ONE condition for both? – Mickaël Leger Feb 20 '18 at 14:11

4 Answers4

1

&& has higher precedence than ||, so you might want to rearrange your conditions, or put parentheses around the second group. Then just write the second part in the same block, like this.

if (strstr($status, "value1") !== false || (isset($_POST['searchOrder']) && $_POST['searchOrder']!=''))
{
    $userToSearch = "WHERE name='Conformed'";
    $hide .= 'style="display: none;"';       
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • 1st condition : i want to display rows where `name='Conformed'";` but they are not displaying, but only 2nd condition is working `$hide .= 'style="display: none;"'; ` –  Feb 20 '18 at 14:05
  • I'm sorry, I don't understand your comment. – Federico klez Culloca Feb 20 '18 at 14:07
  • i am getting result for this : `$hide .= 'style="display: none;"'; ` , but not for `$userToSearch = "WHERE name='Conformed'";` –  Feb 20 '18 at 14:08
  • I still don't understand what you're trying to say. If you `echo $userToSearch` after the `if`, does it echo? From that point on, I don't know what you're doing with that variable, so I'm not sure how to help. – Federico klez Culloca Feb 20 '18 at 14:09
  • okay, i will tell cleary, there is one row in table which have `name` column with value = `Confirmed` , that row is not displaying..... –  Feb 20 '18 at 14:10
  • yes , once i done `echo $userToSearch` it displayed result : `ORDER DATE WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed' WHERE name='Conformed'` –  Feb 20 '18 at 14:12
  • Then it worked, wouldn't you agree? But at that point I don't know what you do with `$userToSearch` (I suppose you're appending it to some query), and it is out of scope for this question. – Federico klez Culloca Feb 20 '18 at 14:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/165496/discussion-between-vickey-colors-and-federico-klez-culloca). –  Feb 20 '18 at 14:14
0

Something like that?

if((isset($_POST['searchOrder']) && $_POST['searchOrder']!='') || strstr($status, "value1") !== false) {
       $userToSearch = "WHERE name='Conformed'"; 
       $hide .= 'style="display: none;"';
   }
Arsenio Siani
  • 261
  • 3
  • 10
0

If you need to satisfy both conditions then do something like this :

if (((strstr($status, "value1") !== false)) &&  (isset($_POST['searchOrder']) && $_POST['searchOrder']!='')))
                  {
                     $userToSearch = "WHERE name='Conformed'";   
                     $hide .= 'style="display: none;"';              
                  }
prakash tank
  • 1,269
  • 1
  • 9
  • 15
0

If you want two conditions alternatively you should remember about grouping.

(condition1) || (condition2)

In your case you've got && condition as part of second case, it is not grouped so it is processing first your OR condition between condition1 and first part of condition2, than last AND which is not you wanted.

DevilaN
  • 1,317
  • 10
  • 21