Reputation: 5
im new in codeigniter
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/siswa_spp.php
Line Number: 39
and i cant solve that error, here is my controller :
function siswa($id_siswa)
{
$data['spp'] = $this->M_spp->detail_spp($id_siswa)->row();
$data['temp'] = $this->M_spp->temp_spp($id_siswa)->row();
$data['list'] = $this->M_spp->list_temp($id_siswa)->result();
$data['bulan'] = $this->M_spp->listbulan($id_siswa);
$this->load->view('includes/head');
$this->load->view('includes/nav_header');
$this->load->view('includes/nav_sidebar');
$this->load->view('siswa_spp',$data);
$this->load->view('includes/foot');
}
my model :
function listbulan($id_siswa)
{
$this->db->select('*');
$this->db->from('tb_spp');
$this->db->where('id_siswa',$id_siswa);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$result = $query->result();
}
return $result;
}
and my view :
<?php
foreach ($bulan as $b) {
echo $b->bulanPembayaran;
}
?>
i dont know where the error in my code, and sorry for bad english
Upvotes: 0
Views: 5528
Reputation: 1
check first $data['bulan'] is array or not
$this->load->view('siswa_spp',array("data" =>$data['bulan']));
pass like this in view..!!
Upvotes: 0
Reputation: 2034
Check in your model if object found or not
function listbulan($id_siswa)
{
$this->db->select('*');
$this->db->from('tb_spp');
$this->db->where('id_siswa',$id_siswa);
$query = $this->db->get();
$result = false;
if ($query->num_rows() > 0) {
$result = $query->result();
}
return $result;
}
Check in your view as well.
<?php
if($bulan){
foreach ($bulan as $b) {
echo $b->bulanPembayaran;
}
}
?>
Upvotes: 2