CodeIgniter Forums
Accessing associative arrays from models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Accessing associative arrays from models (/showthread.php?tid=46307)



Accessing associative arrays from models - El Forum - 10-26-2011

[eluser]condoace[/eluser]
I want to grab some data from a model and pass it to a controller. How do I turn the $query variable in my controller into a set of independant variables so I can pass them to another method etc.. here is my code thus far:

I want the variable $my_id to store the id value from the model.

CONTROLLER
Code:
$this->load->model('Model_employees');
  
   $query = $this->Model_employees->validate_user();
  
   $my_id = $query->id;
  
   if($query == true) // if the user's credentials validated...
   {
    $data = array(
    
     'user_id' => $my_id,
    
     'login_email' => $this->input->post('login_email'),
    
     'logged_in' => true
    );
    
    $this->session->set_userdata($data);
    
    redirect('employees/index');
   }
   else // incorrect username or password
   {
    echo 'not working';
   }

MODEL

Code:
function get_my_credits($id) {
  
   $query = "SELECT * FROM credit_history WHERE id = '".$id."' ";
  
   $result = $this->db->query($query);
  
   return $result->result();
    
  }