Osclass forums

Support forums => General help => 3.6.x => Topic started by: shaan1988 on October 18, 2016, 11:14:17 pm

Title: Multiple conditions inside if not working
Post by: shaan1988 on October 18, 2016, 11:14:17 pm
Code: [Select]
<?php if(( (osc_item_category() != 'Motorcycles'))||((osc_item_category() != 'Brides Wanted'))) { ?>
                        <input type="image" src="/oc-content/themes/bender/buy2.png" alt="Submit" width="50%"><?php }else{ ?>&nbsp;<br><br><?php ?>

The above is not working but the code below works please help me.

Code: [Select]
<?php if(osc_item_category() != 'Motorcycles') { ?>
                        <input type="image" src="/oc-content/themes/bender/buy2.png" alt="Submit" width="50%"><?php }else{ ?>&nbsp;<br><br><?php ?>
Title: Re: Multiple conditions inside if not working
Post by: fog on October 18, 2016, 11:42:50 pm
Do you mean:

Code: [Select]
<?php if( osc_item_category() != 'Motorcycles' or osc_item_category() != 'Brides Wanted') { ?>
<!-- your code -->
<?php ?>

Regards
Title: Re: Multiple conditions inside if not working
Post by: shaan1988 on October 20, 2016, 01:35:18 pm
Yes but it is not working
Title: Re: Multiple conditions inside if not working
Post by: fog on October 20, 2016, 05:07:09 pm
Hi, will working if the name of categories are on same language. Otherwise will not working on different languages, unless you use proper condition for current language by user.

Maybe is not the best solution with "if and else" with a lot of languages, but with few languages you can do something like:

Code: [Select]
<?php 
if(osc_current_user_locale() == en_US) {
if(
osc_item_category() == 'Art - Collectibles' or osc_item_category() == 'Animals' ) {
/* your code */
}
} elseif(
osc_current_user_locale() == pt_PT) {
if(
osc_item_category() == 'Arte - Colecionáveis' or osc_item_category() == 'Animais' ) {
/* your code */
}
}
?>


My suggestion is you use category Id and forget category by name, this a way you avoid condition to current language by user.

You just need change the number ID for your category numbers you really need.

Code: [Select]
<?php if(osc_item_category_id() == '9' or osc_item_category_id() == '10' ) {?>
you can see this text on your items on these categories ID
<?php ?>

But both codes will working.

Regards
Title: Re: Multiple conditions inside if not working
Post by: frosticek on October 21, 2016, 01:04:00 am
@shaan1988
It is more comfortable to compare on category id instead of name.
Code: [Select]
osc_item_category_id()
Title: Re: Multiple conditions inside if not working
Post by: shaan1988 on October 21, 2016, 05:32:54 am
FOG and MB Themes, thanks for your immense support.
It is now working  with the codes written below

Code: [Select]
<?php
if(osc_item_category()!='Motorcycles'){
......
My Code......}
else if(
osc_item_category()!='Brides Wanted'){
....... 
My Code.....}
else{
...... 
My Code......
}
?>