【发布时间】:2021-09-12 09:17:48
【问题描述】:
我在 foreach 循环中编写了一个数据库查询,在某些情况下,该查询使用不同的参数执行了 100 多次。
当 foreach 循环仅重复几轮时,脚本运行良好。
除了重新安排查询以在单个请求中获取所有数据之外,还有其他替代方法可以让我以有效的方式使用 foreach 循环运行脚本吗?
我当前的脚本
// some where clauses here
$re = $this->db->get('cash_collection')->result();
$d=0;
foreach($re as $area){ // this loop runs 100+ rounds
// call a function with single db query
$re[$d]->area_paid = $this->Payment_m->get_inTotalForNormal($area->fka_id,$area->in_date);
$d++;
}
return $re;
【问题讨论】:
标签: php mysql codeigniter activerecord foreach