0
votes

I need to Ignore the variables in IF condition which have the value "All".

Here are the conditions. $one and $two are GET/POST variables

case1: If $one == 'All' and $two = 'Sometext'

if($two == $DynamicValue2)
{
//display data
}

Case2: If $one == 'text' and $two = 'All '

if($one== $DynamicValue1)
{
//display data
}

Case3: If $one == 'text' and $two = 'text'

if($one == $DynamicValue1 && $two == $DynamicValue2)
{
//Display Data
}

Case4: If $one == 'All' and $two = 'All'

No need to write/ Check IF condition here.

I tried the following code but doesn't work

if(isset($one) && $one!= 'All')
{
if($one == $DynamicValue1): // First IF
}

if(isset($two) && $two!= 'All')
{
if($two == $DynamicValue2): // Second IF
}

//dispaly data

if(isset($one) && $one!= 'All')
{
endif; // to close First IF condition
}

if(isset($two) && $two!= 'All')
{
endif; // to close Second IF condition
}

I thought the above code satisfies all the cases which I've mentioned here. But no use. Any suggestions?

3
Could you indent your code to make it easier to understand how you want it to react?h2ooooooo
you cant start a if statement in one if statement and end it in another if statement.Viswanath Polaki
whats wrong with normal nested ifs? if(cond){if(other){//do stuff}}Steve
You cannot conditionally open and close if statements. Simply nest your conditions logically inside regular if (..) { if (..) { .. } } blocks.deceze
why all the downvotes? this question shows an attempt to do something, and obviously the OP's lack of PHP experience has resulted in this..CᴴᵁᴮᴮʸNᴵᴺᴶᴬ

3 Answers

0
votes

You can combine statements in one if:

if(isset($one) && $one!= 'All' && $one == $DynamicValue1 &&
    isset($two) && $one!= 'All' && $two == $DynamicValue2)
{
    //dispaly data
}

This code will check if isset $one variable and $one not equal to 'All' and $one equal to $DynamicValue1 and the same with $two variable

0
votes

Are you trying to do that?:

if(isset($one) && $one!= 'All') {
    if($one == $DynamicValue1) { 
        // make this
    }

    if (isset($two) && $two == $DynamicValue2) {
        // make that
    }
}
0
votes

Finally I could able to resolve my issue.

if($one == 'All')
{
$one = $DynamicValue1;

}

if($two == 'All')
{
$two = $DynamicValue2

}

Then I write the condition like follows

if($one == $DynamicValue1 && $two == $DynamicValue2)

{

//my data here


}

So it satisfies all the conditions.

If $one has a value of 'All' then it overwrites that value with $DynamicValue1. So it would be always true. If it's other than 'All' It would check with $DynamicValue1 in IF condition.

Similarly for variable $two also

I wrote this logic myself. I tested all scenarios and working fine.

Suggest me If I'm wrong.