smehsoud smehsoud - 1 year ago 50
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

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 Source

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

if(($this->uri->segment(1)=='reports') || ($this->uri->segment(2)=='manageflyers' && $this->uri->segment(3)=='save')){ 
    //do nothing
    //some js code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download