I'm trying to learn the MVC approach using CodeIgniter and I'm stuck with trying to display the results of the SQL query to the view. I'm using the method binding way as I've heard its secure with escaping variables when writing SQL queries.
Here's the model:
public function getuser_id()
{
$this->db->select('id')->from('users')->where('email', $this->session->userdata('email'));
$query = $this->db->get();
}
Here's the controller:
public function members()
{
if ($this->session->userdata('is_logged_in'))
{
$data['title'] = 'Members Page';
$this->load->model('model_users');
$data['uid'] = $this->model_users->getuser_id();
$this->load->view('members', $data);
}
else
{
redirect('main/restricted');
}
}
The view simply does echo $uid;. All I want to do is print the user ID on the screen. I believe that the issue lies in the getuser_id() function. The profiler says that the query is being executed on the page but I am not seeing a result. The data definitelythere exists in the database.
Any help would be greatly appreciated!
getuser_id()function.