hello there please help me am stuck on error: undefined variable query: A PHP Error was encountered Severity: Notice
Message: Undefined variable: query
Filename: users/all_users.php
Line Number: 14
here is my controller: controller code for project
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_manager extends CI_Controller{
function _construct(){
parent::_construct();
$this->load->helper('form');
$this->load->helper('url');
$this->load->helper('security');
$this->load->model('Users_manager_model');
$this->load->database();
}
public function index(){
redirect('users/view_users');
}
public function view_users(){
$data['query'] = $this->user_manager_model->get_all_users();
$this->load->view(users/all_users, $data);
}}
And here is my model
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User_manager_model extends CI_Model{
function construct(){
parent::__construct();
}
public function get_all_users(){
return $this->db->get('users');
}}
finally here is my view for my users
<?php if ($query->num_rows() > 0 ) : ?>
<table table-bordered table-responsive style="margin-top: 20px">
<thead>
<tr>
<td>Id</td>
<td>First Name</td>
<td>Last Name</td>
<td>Employee No.</td>
<td>Department</td>
<td>Created</td>
<td>Is Active</td>
<td colspan="2">Actions</td>
</tr>
</thead>
<?php foreach ($query->result() as $row) : ?>
<tbody>
<tr>
<td><?php echo $row->id; ?></td>
<td><?php echo $row->fname; ?></td>
<td><?php echo $row->lname; ?></td>
<td><?php echo $row->emp_no; ?></td>
<td><?php echo $row->dept; ?></td>
<td><?php echo date("d-m-y", $row->cdate); ?></td>
<td><?php echo ($row->is_active ? 'Yes' : 'No'); ?></td>
<td><?php echo anchor('users/edit_user/'.$row->id, 'Edit'); ?></td>
<td><?php echo anchor('users/delete_user/'.$row->id, 'Delete'); ?></td>
</tr>