I store the return value from my model in a $result
:
$result = $this->absensi_m->absensi();
Based on what i return in the absensi()
function, the value of $result
will be one of these :
- FALSE
- 'sudah absen' (a String)
- 1 (indicating success)
Then i try to see the $result
value using echo $result;
and it returns 1
But, i get a strange error when i try to use $result
for some validations :
if($result == FALSE)
$data['result'] = 'Anda Belum Terdaftar, Silahkan Daftar Dahulu :D';
else if($result == 'sudah absen')
$data['result'] = 'Anda Sudah Absen Hari Ini :D';
else
$data['result'] = 'Selamat Datang, '.$this->input->post('txtNama').'! ^^';
Although the value of $result
is 1, the second if ($result == 'sudah absen'
) always return TRUE.
Whats going on here?Thanks :D
This is the absensi()
function in my model :
public function absensi() {
$nama = $this->input->post('txtNama');
$tanggal = date('Y-m-d', now());
$this->db->select('umat_id');
$terdaftar = $this->db->get_where('msumat', array('nama' => $nama));
$row = $terdaftar->row_array();
$sudah_absen = $this->db->get_where('msabsensi', array('umat_id' => $row['umat_id'], 'absensi_tanggal' => $tanggal));
if($terdaftar->num_rows() != 0 && $sudah_absen->num_rows() == 0)
{
$data_umat = array(
'umat_id' => $row['umat_id'],
'status' => 'H',
'absensi_tanggal' => date('Y-m-d')
);
return $this->db->insert('msabsensi', $data_umat);
}
else if($sudah_absen->num_rows() != 0)
return 'sudah absen';
else
return FALSE;
}
ANSWER : I will answer here because you may be confused with a lot of comments/conversation.
I realized whats going on by using var_dump()
and echo
(Thanks to both answers below):
$result = $this->absensi_m->absensi();
var_dump($result);
echo $result;
The var_dump()
returns bool(true)
while the echo
returns 1. This means that this problem is occured because i think the $result
value is 1(integer), while the real value is TRUE(bool).
The conclusion is : echoing a variable with a TRUE(bool) value will result 1(integer), so use the var_dump()
instead of echo
.