Welcome Guest, Not a member yet? Register   Sign In
Some basic logic help, controllers and models
#1

[eluser]ywftdg[/eluser]
Its been a few years since I have gotten dirty with CI, but here i am back at it. I am trying to understand the logic of one thing though. I have a current controller, which loads up some data into an array. I then loop through that array in the view to get the tables. My problem is, I am trying to add another array into this data in the controller, but no idea how to get this to work right.

In my controller function, I am trying to add something like this:

Code:
foreach ($data['application_list'] as $app) {
    $this->db->where('id', $app->user_id);
    $data['application_list']['username'] = $this->user_model->get_one_user();
}

basically, I need to add in this 'username' value to the array $data['application_list'].

Any ideas on this? I hope this makes some sense?
#2

[eluser]Bart Mebane[/eluser]
Without seeing the rest of your code I'm not sure this is the best way to do it, but you can try this:
Code:
$list = array();
foreach ($data['application_list'] as $app) {
    $app->username = $this->user_model->get_one_user($app->user_id);
    $list[] = $app;
}
$data['application_list'] = $list;
Your model would look like
Code:
function get_one_user($id)  {
    $this->db->where('id', $id);
    ...
}




Theme © iAndrew 2016 - Forum software by © MyBB