A PHP Error was encountered
Severity: Notice
Message: Undefined variable: daftar_user
Filename: views/daftar_user.php
Line Number: 17
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/daftar_user.php
Line Number: 17
Nik Nama Tempat Lahir Tanggal Lahir Umur Status Jenis Kelamin alamat
Nik Nama Tempat Lahir Tanggal Lahir Umur Status Jenis Kelamin alamat
#controller
function penduduk()
{
$this->load->view('main');
}
function simpan_penduduk()
{
$this->load->model('user_model');
$this->user_model->simpan_penduduk();
}
function user()
{
$this->load->model('user_model');
$data['judul']= 'menampilkan data penduduk';
$data['daftar_user'] = $this->user_model->get_user_all();
$this->load->view('daftar_user', $data);
}
}
#user_model.php
<?php
/**
*
*/
class User_model extends CI_Model {
function simpan_penduduk()
{
$simpan_data=array(
'no_kk' => $this->input->post('no_kk'),
'nik' => $this->input->post('nik'),
'nama' => $this->input->post('nama'),
'tempat_lahir' => $this->input->post('tempat_lahirt'),
'tanggal_lahir' => $this->input->post('tanggal_lahir'),
'umur' => $this->input->post('umur'),
'status' => $this->input->post('status'),
'jenis_kelamin' => $this->input->post('jenis_kelamin'),
'alamat' => $this->input->post('alamat'),
);
$simpan = $this->db->insert('penduduk', $simpan_data);
return $simpan;
}
function get_user_all()
{
$query =$this->db->query("SELECT * FROM penduduk ORDER BY nik DESC");
return $query->result();
}
}
?>
#daftar_user.php
<table border="1">
<thead>
<tr>
<th>Nik</th>
<th>Nama</th>
<th>Tempat Lahir</th>
<th>Tanggal Lahir</th>
<th>Umur</th>
<th>Status</th>
<th>Jenis Kelamin</th>
<th>alamat</th>
</tr>
</thead>
<tbody>
<?php foreach($daftar_user as $user) : ?>
<tr>
<td><?php echo $user->nik; ?></td>
<td><?php echo $user->nama; ?></td>
<td><?php echo $user->tempat_lahir; ?></td>
<td><?php echo $user->tanggal_lahir; ?></td>
<td><?php echo $user->umur; ?></td>
<td><?php echo $user->status; ?></td>
<td><?php echo $user->jenis_kelamin; ?></td>
<td><?php echo $user->alamat; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th>Nik</th>
<th>Nama</th>
<th>Tempat Lahir</th>
<th>Tanggal Lahir</th>
<th>Umur</th>
<th>Status</th>
<th>Jenis Kelamin</th>
<th>alamat</th>
</tr>
</tfoot>
</table>
答案 0 :(得分:0)
很明显,daftar_user未在您发布到视图的代码中定义