I mark an error in my visa, it says that the variable row is not defined, this error marks me when I do not have data in the database

0
foreach($data['prestamos'] as $row):
            /*inicia inspeccionar abonos*/
            $prestamos   = $this->prestamosModel->getAbonosPrestamoInicio($row->pr_id_prestamo );
            $suma_prestamos = 0.00;
            if($prestamos){
                foreach($prestamos  as $row2):
                    if($row2->pa_monto>0){
                        $suma_prestamos = $suma_prestamos+$row2->pa_monto;
                    }
                endforeach;
            }
            $row->suma_prestamos = $suma_prestamos;
            endforeach;


        $this->load->view('control/pagina_inicio', $data);
    
asked by Cesar Vieyra 10.08.2017 в 23:16
source

1 answer

1

To avoid this error, you must verify that $data['prestamos'] is not empty, add this line:

if (!empty($data['prestamos'])) {
    foreach($data['prestamos'] as $row):
}
    
answered by 10.08.2017 / 23:17
source