Welcome Guest, Not a member yet? Register   Sign In
IF Conditions statement not working in my controller
#1

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');
}
Reply
#2

It is because you use comparison with strong typing. If the parameters are expected to be numbers, cast them to integer type.
Reply
#3

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.
Reply
#4

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.
Reply
#5

Php === is strict and evaluates variable types as well as the value. An empty string does not have a zero integer value...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB