Here's my controller call "a_porto"
public function index() {
$this->load->model('a_porto_models');
$data = array();
$data['tampil'] = $this->a_porto_models->get_crud_all();
$this->load->view('a_porto_view', $data);
}
Here's my model call "a_porto_models"
function get_crud_all() {
$query = $this->db->get('prototype');
return $query->result();
}
And than my view call "a_porto_views"
<?php $tampil = array(); ?>
<?php foreach ($tampil as $a){ ?>
<tr>
<td><?php echo $a->id_proto; ?></td>
<td><?php echo $a->foto; ?></td>
<td><?php echo $a->nama_pro; ?></td>
<td><?php echo $a->tahun; ?></td>
<td><?php echo $a->lokasi; ?></td>
<td><?php echo $a->deskripsi; ?></td>
</tr>
<?php } ?>
What I've to do? My code doesn't show an error :(
Change to this code:
<?php foreach ($tampil as $a){ ?>
<tr>
<td><?php echo $a->id_proto; ?></td>
<td><?php echo $a->foto; ?></td>
<td><?php echo $a->nama_pro; ?></td>
<td><?php echo $a->tahun; ?></td>
<td><?php echo $a->lokasi; ?></td>
<td><?php echo $a->deskripsi; ?></td>
</tr>
<?php } ?>
You see null result because you reset your array to be empty. when its already have content from the controller sent to the view
Remove $tampil = array(); and try again. You are basically setting your result to an empty array there.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.