In post Codeigniter result_array() returning one row https://stackoverflow.com/users/315828/xbonez answer was like this
function getAllUsers()
{
$rows = array(); //will hold all results
$query = $this->db->get('users');
foreach($query->result_array() as $row)
{
$rows[] = $row; //add the fetched result to the result array;
}
return $rows; // returning rows, not row
}
In your controller:
$data['users'] = $this->yourModel->getAllUsers();
$this->load->view('yourView',$data);
In your view
//in your view, $users is an array. Iterate over it
<?php foreach($users as $user) : ?>
<p> Your first name is <?= $user['fName'] ?> </p>
<?php endforeach; ?>
initiating query from controller and the query result is in $data['users'], but in view we are iterating in as $users. why this is?