smehsoud smehsoud - 2 months ago 6
PHP Question

OR " || " opreator not working in if statement in php

I am using codeigniter and wants to shwo the js code only if following condition true

<?php
if(($this->uri->segment(1)!='reports') || ($this->uri->segment(2)!='manageflyers' && $this->uri->segment(3)!='save')){?>
//some js code
<?php }?>


But i does not work please help where i am making the mistake.

Answer

A couple of != with an OR || will always equal true because that string variable will only equal one thing and not be the other

so your code will work like this

<?php 
if(($this->uri->segment(1)=='reports') || ($this->uri->segment(2)=='manageflyers' && $this->uri->segment(3)=='save')){ 
    //do nothing
 }else{
    //some js code
 }