I am trying to fetch data from a table, I created a controller, model and view but when I try to open view, I am getting two errors one is Message: Undefined variable: u_list and another one is Message: Invalid argument supplied for foreach() I am using CodeIgniter 3.1.9
Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class UserFetch extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->database();
$this->load->model('userinsert');
}
public function index() {
$data['u_list']=$this->userinsert->select();
$this->load->view('dashboard', $data);
}
}
?>
Model
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class UserInsert extends CI_Model {
function __construct() {
parent::__construct();
}
function user_insert($data) {
$this->db->insert('users', $data);
}
public function select() {
$query = $this->db->get('users');
return $query;
}
}
?>
View
<tbody>
<?php
foreach ($u_list as $row) {
?>
<tr>
<td><?php echo $row->first_name;?></td>
<td><?php echo $row->last_name;?></td>
</tr>
<?php }
?>
</tbody>
Help me with this guys
var_dump($this->_ci_cached_vars);tell me what are you getting therearray (size=0) empty$this->load->view('dashboard', ['u_list' => $this->userinsert->select()]);