![]() |
IF Conditions statement not working in my controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: IF Conditions statement not working in my controller (/showthread.php?tid=65219) |
IF Conditions statement not working in my controller - ezenna - 05-16-2016 I am new to Codeigniter. For some reasons if statement is not evaluating properly within my controller. I will appreciate any help. See my code snipet below public function states(){ $this->load->view('sap/header'); $state = str_replace ("%20", " ", $this->uri->segment(3, 0)); $lga = str_replace ("%20", " ", $this->uri->segment(4, 0)); $pms = str_replace ("%20", " ", $this->uri->segment(5, 0)); //plazas markets and shops $data['state'] = $state; $data['lga'] = $lga; $data['pms'] = $pms; //$data['plaza'] = $plaza; $id = $this->welcome_model->getStateID($state); $stateid = $id[0]['state_id']; //$lgaid = $lgaid[0]['lga_id']; if(!($plaza === 0)){ } // elseif(!($lga=== 0)){ } else (!($pms === 0)){ } $this->load->view('sap/footer'); } RE: IF Conditions statement not working in my controller - ivantcholakov - 05-16-2016 It is because you use comparison with strong typing. If the parameters are expected to be numbers, cast them to integer type. RE: IF Conditions statement not working in my controller - John_Betong - 05-16-2016 Further to ivantcholakov's suggestion, insert the following in the first line of your public function states() { error_reporting(-1); ini_set('display_errors', 'true'); Both errors and warnings should show and you can change the script. Also str_replace(...); always and only returns a string or error. RE: IF Conditions statement not working in my controller - Andy N - 05-17-2016 In general with PHP, only use === if you understand why you are using it, and you have a specific reason (for example you really need to know that something is boolean false rather than just an empty string which evaluates to false), in most cases == is the operator you are looking for. RE: IF Conditions statement not working in my controller - John_Betong - 05-17-2016 Php === is strict and evaluates variable types as well as the value. An empty string does not have a zero integer value... |