ldoozer Posted July 29, 2008 Share Posted July 29, 2008 can anyone see why my statement is not working? if ($TEMPLATE['id'] !="11" || $TEMPLATE['id'] !="15" || $TEMPLATE['id'] !="16" || $TEMPLATE['id'] !="17") { ?> <table id="productOptionsTbl"> <?=$TEMPLATE['options'];?> <tr> <td class="itemOptionLabel">Add to basket:</td> <td class="itemOptionSelect"> <input name="quantity" type="text" value="1" size="2" /> item(s) <input type="hidden" name="id" value="<?=$TEMPLATE['id'];?>" /> <input name="action" type="hidden" value="add" /> <input type="submit" class="submitStyled" value="Buy now" /> </td> </tr> </table> <? } ?> Link to comment https://forums.phpfreaks.com/topic/117146-solved-php-or-statement/ Share on other sites More sharing options...
Xurion Posted July 29, 2008 Share Posted July 29, 2008 I tried it and it worked fine with no errors. Looks like your if statement is looking for string literals, and not numbers. Try: if ($TEMPLATE['id'] !=11 || $TEMPLATE['id'] !=15 || $TEMPLATE['id'] !=16 || $TEMPLATE['id'] !=17) { Link to comment https://forums.phpfreaks.com/topic/117146-solved-php-or-statement/#findComment-602563 Share on other sites More sharing options...
harsh00008 Posted July 29, 2008 Share Posted July 29, 2008 <? } ?> at the end I think this is a syntax error Link to comment https://forums.phpfreaks.com/topic/117146-solved-php-or-statement/#findComment-602568 Share on other sites More sharing options...
Xurion Posted July 29, 2008 Share Posted July 29, 2008 Assuming he has short tags turned on, that is fine. Link to comment https://forums.phpfreaks.com/topic/117146-solved-php-or-statement/#findComment-602606 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2008 Share Posted July 29, 2008 You are using negative logic (the !) with an OR function. The conditional statement will always be true because the only way it would be false is if the variable being tested simultaneously had all the value at the same time. Pick one of the values and go though the statement and see what it evaluates as - Try 17 - if (17 !="11" || 17 !="15" || 17 !="16" || 17 !="17") { ?> this gives - if (TRUE || TRUE || TRUE || FALSE) { ?> You need to change the OR's to AND's - if ($TEMPLATE['id'] !="11" && $TEMPLATE['id'] !="15" && $TEMPLATE['id'] !="16" && $TEMPLATE['id'] !="17") { ?> You can also place the list of values into an array and use the in_array() function to test if the variable matches something in the array or use the not (!) !in_array(...) to test if the variable does not match something in the array. Link to comment https://forums.phpfreaks.com/topic/117146-solved-php-or-statement/#findComment-602617 Share on other sites More sharing options...
ldoozer Posted July 29, 2008 Author Share Posted July 29, 2008 Thank you all very much for the help, heres what i ended up doing to get it working: <? /*Added to hide add to cart button on specific products */ if ($TEMPLATE['id'] !="11" && $TEMPLATE['id'] !="15" && $TEMPLATE['id'] !="16" && $TEMPLATE['id'] !="17") { ?> <table id="productOptionsTbl"> <?=$TEMPLATE['options'];?> <tr> <td class="itemOptionLabel">Add to basket:</td> <td class="itemOptionSelect"> <input name="quantity" type="text" value="1" size="2" /> item(s) <input type="hidden" name="id" value="<?=$TEMPLATE['id'];?>" /> <input name="action" type="hidden" value="add" /> <input type="submit" class="submitStyled" value="Buy now" /> </td> </tr> </table> <? } ?> Link to comment https://forums.phpfreaks.com/topic/117146-solved-php-or-statement/#findComment-602687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.