我想在codeigniter中弄清楚這件事情,但因爲我是初學者,所以在查找解決方案時遇到了一些麻煩。Codeigniter將數組合併到一個數組中
我有一個名爲tasks
的表和另一個名爲progress
的表。因此,在tasks
表中插入多個任務,並將這些任務的進度插入到progress
表中。我正在使用不同的表來跟蹤進度,因爲我可能需要稍後跟蹤每項任務的進度歷史記錄。
$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));
};
所以我試圖做的是既$task
和$progress
的條目添加到陣列,這樣我可以遍歷並顯示在時間的任務綜合作用的結果。
有在tasks
表中的兩個條目和$tasks
值是:
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"
}
}
有在progress
表中的兩個條目,每個$progress
值:
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"
}
}
這幫助。將進度對象添加到'$ task-> progress_list',現在我可以將進度值作爲'$ task-> progress_list-> percentage'來訪問。謝謝 – prakashchhetri