Codeigniter merge arrays to a single array

I am trying to figure out this thing in codeigniter, but because I am a beginner, I am having some trouble finding the solution for it.

I have a table named tasks and another table named progress. So a number of tasks are inserted in tasks table and progress for those tasks are inserted in progress table. I am using different table to track progress because I may need to track down the progress history for each tasks later on.

$all_tasks = $this->task_m->get_by(array('user_id'=> $this->session->userdata('id')));

foreach ($all_tasks as $task) {
    $progress = $this->progress_m->get_by(array('task_id'=> $task->id));

};

So what I am trying to do is add the entries of both the $task and $progress to an array so that I can loop through it and display the combined result for a task at a time.

There are two entries in tasks table and the value of $tasks is :

array(2) {
  [0]=>
  object(stdClass)#24 (8) {
    ["id"]=>
    string(1) "6"
    ["user_id"]=>
    string(1) "2"
    ["name"]=>
    string(28) "Sample task to do sometihing"
    ["description"]=>
    string(28) "Sample task to do sometihing"
    ["priority"]=>
    string(4) "high"
    ["status"]=>
    string(7) "pending"
    ["created"]=>
    string(19) "2014-02-27 23:26:09"
    ["modified"]=>
    string(19) "2014-02-27 23:26:09"
  }
  [1]=>
  object(stdClass)#25 (8) {
    ["id"]=>
    string(1) "7"
    ["user_id"]=>
    string(1) "2"
    ["name"]=>
    string(13) "Sample task 2"
    ["description"]=>
    string(11) "Sample desc"
    ["priority"]=>
    string(1) "1"
    ["status"]=>
    string(0) ""
    ["created"]=>
    string(19) "2014-02-28 00:20:17"
    ["modified"]=>
    string(19) "2014-02-28 00:20:17"
  }
}

There are two entries in progress table and the value for each $progress is :

array(1) {
  [0]=>
  object(stdClass)#26 (6) {
    ["id"]=>
    string(1) "1"
    ["task_id"]=>
    string(1) "6"
    ["percentage"]=>
    string(2) "68"
    ["description"]=>
    string(17) "About to complete"
    ["created"]=>
    string(19) "2014-02-18 00:00:00"
    ["modified"]=>
    string(19) "2014-02-12 00:00:00"
  }
}

array(1) {
  [0]=>
  object(stdClass)#27 (6) {
    ["id"]=>
    string(1) "2"
    ["task_id"]=>
    string(1) "7"
    ["percentage"]=>
    string(2) "56"
    ["description"]=>
    string(6) "Sample"
    ["created"]=>
    string(19) "2014-02-05 00:00:00"
    ["modified"]=>
    string(19) "2014-02-14 00:00:00"
  }
}

Answers


You're almost there:

$all_tasks = $this->task_m->get_by(array('user_id'=> $this->session->userdata('id')));

foreach ($all_tasks as $task) {
    $task->progress_list = $this->progress_m->get_by(array('task_id'=> $task->id));
};

Need Your Help

jgit - Get the list of changed files after a pull

java git jgit

I would like to know how I can retrieve the list of changed files after a pull request.

How can I make the button text change, from text to an empty name with a delay?

python python-3.x button tkinter tk

I'm using tkinter library for the GUI. Basically I'm creating 4 buttons using a for loop, each having a random number as their text. Now I got stuck when trying to implement a method which allows the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.