I tried to count the amount of data in the manajemen_user table using num_row() in codeigniter.
here my table(manajemen_user):
id|nama|username|email|password|jabatan
1|Admin|admin|[email protected]|123|Administrator
here my controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Statistik extends CI_Controller
{
public function index()
{
//load model
$this->load->model('statistik_model');
$data = array();
$data['jumlah_user'] = $this->statistik_model->total_rows();
//load view
$this->load->view('backend/index',$data);
}
}
here my model
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Statistik_model extends CI_Model
{
function total_rows() {
$query = $this->db->get('manajemen_user');
return $query->num_rows();
}
}
and here my view :
<div class="col-lg-3 col-xs-6">
<?php foreach ($jumlah_user as $total_user):?>
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3><?php echo $total_user ?></h3>
<p>Jumlah User</p>
</div>
<div class="icon">
<i class="ion ion-person-add"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
</div>
<?php endforeach; ?>
</div>
but i have an error like this in my view.
Message: Undefined variable: jumlah_user
Message: Invalid argument supplied for foreach()
I do not know where the mistake is. sorry i am new in codeigniter. can anyone help me? Thank you.