Returning String when If is true, and Boolean when If is false.

Thanks in advance for any help on this issue!

I want the function get_single to return the $employeeList ARRAY when the IF statement is correct, and a BOOLEAN when the IF is not correct, and therefore FALSE.

Right now I’m only getting a BOOLEN when I run a unit test (using CodeIgniter). What am I doing wrong?

[php]

public function get_single()
{ 
 //--ID from Post
        $id = $this->input->post('empid');
        settype($id, "integer"); 
        
// Query        
    $query = $this->db->query("SELECT * FROM employees WHERE id= $id;");
            $employeeList = $query->result_array();

// If rows results are less than 0 then return false.
        if ($query->num_rows($employeeList) > 0) {

            return $employeeList; 
        }
        
// If value is less than 0        
        else return false;        
    
}

[/php]

You could simply remove the else. I believe that’s a syntax error anyways.

[php]
if ($query->num_rows() > 0) {
return $employeeList;
}
return false;
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service