在笨,我有以下的模型多維數組
function get_item_history($id)
{
//from metadata_history get item_id and corresponding metadata
$this->db->from('metadata_history')->where(array('id'=>$id, 'current_revision'=> "TRUE"));
$query = $this->db->get();
$result = $query->result_array(); //store this in an array
// loop through the array
foreach($result as $key => $row)
{
$array = array('item_id'=>$row['item_id'], 'current_revision'=> "TRUE");
$this->db->from('history')->where($array);
$query = $this->db->get();
$row['items'] = $query->result_array(); //
$result[$key] = $row;
}
return $result;
}
的問題是,這會導致多個查詢SQL表顯著增加了執行時間(分頁是不是一種選擇)
我希望能夠將第一個查詢結果作爲一個數組傳遞給第二個查詢,這樣我就只需要一個數據庫,然後從結果中重建一個數組。
我應該如何重寫這段代碼(第二部分)?它會更快(我想是這樣)?
編輯
重建從結果數組是什麼flummoxing我。
http://www.phpbuilder.com/board/showthread.php?t=10373847
這就是我可能想,但我沒有跳
謝謝,請將您的建議用於我的解決方案 – 2010-11-03 04:45:15