Advertisement:

Author Topic: Multiple conditions inside if not working  (Read 984 times)

shaan1988

  • Newbie
  • *
  • Posts: 3
Multiple conditions inside if not working
« 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 ?>

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: Multiple conditions inside if not working
« Reply #1 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

shaan1988

  • Newbie
  • *
  • Posts: 3
Re: Multiple conditions inside if not working
« Reply #2 on: October 20, 2016, 01:35:18 pm »
Yes but it is not working

fog

  • Hero Member
  • *****
  • Posts: 1062
Re: Multiple conditions inside if not working
« Reply #3 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
« Last Edit: October 20, 2016, 05:27:31 pm by fog »

frosticek

  • Hero Member
  • *****
  • Posts: 3948
Re: Multiple conditions inside if not working
« Reply #4 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()

shaan1988

  • Newbie
  • *
  • Posts: 3
Re: Multiple conditions inside if not working
« Reply #5 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......
}
?>