0

I have a problem with displaying a bunch of data from my database. Getting data from many tables.

My query before was getting all the data in one query then I had managed to find a way on how to optimize it but I'm not satisfied.

foreach($query->result_array() as $row ){  
   $drreturn = $this->getDRReturnAmount($row["idno"],$date1);
   $return_amount[] = $drreturn->return_amount;

   $checkDRServiceNoPayment = $this->checkDRServiceNoPayment($row["idno"],$date1,$date2);

   if($checkDRServiceNoPayment->num_rows() > 0) {
    $minus_item_amount[] = 0;


   $getProductPurchase = $this->getProductPurchase($row["idno"],$date1,$date2);
    $minus_item_amount[] = $getProductPurchase->amount;
            }

        }

btw I'm using datatable. what I did before was I didn't use an array and I put the model functions inside the foreach but it seems that nothing happened even tho I used array.

SAVe
  • 814
  • 6
  • 22
Tristan Ross
  • 117
  • 1
  • 9
  • This PHP code seams to flood the database with the [N + 1 select](https://stackoverflow.com/questions/97197/what-is-the-n1-selects-problem-in-orm-object-relational-mapping) problem.. – Raymond Nijland Jul 04 '19 at 11:36
  • @RaymondNijland i agree. I didnt design the database and i have to adjust myself because we can't rebuild the database. It's an ERP System. – Tristan Ross Jul 04 '19 at 11:40

0 Answers0