Rikesh Rikesh - 14 days ago 6
PHP Question

How can I pass the variables inside loop using this->data[] from controller to view in php CI

for ($i = 0; $i < $count; $i++) {
$this->data["schedule_count"] = $count;
$this->data["user_travels" . $i] = $this->travel_order_model->get_travel_schedule($this->data["user_dates"]{$i}->id);
}


Error:


A PHP Error was encountered


Severity: Notice


Message: Undefined variable: user_travels

Filename: travel_order/travel_order_report_summary.php

Line Number: 212


A PHP Error was encountered

Severity: Warning


Message: Invalid argument supplied for foreach()

Filename: travel_order/travel_order_report_summary.php

Line Number: 213

Answer
for ($i = 0; $i < $count; $i++) {
  $this->data["schedule_count"] = $count;
  $this->data["user_travels"][$i] = $this->travel_order_model->get_travel_schedule($this->data["user_dates"][$i]->id);
}
$this->load->view('your_view_file', $data);

Your View File, You can print data this way,

foreach($user_travels as $travelData){
    print_r($travelData);
}
Comments