在笨,我有以下的模型多维数组
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