So i'm using latest Codeigniter and my problem is that i have this situation where i should use query inside foreach in controller. I have view that shows all production orders in one list, and i want all user made comments and notes underneath them from other table. Quite general situation in coding, but how i should do this with Codeigniter, cause you should keep your SQL clauses in Models.
Before i just fork raw SQL inside controller, i wanted to ask what is more gentle and proper way to achieve this. Thanks!
Controller
<?php
public function show()
{
$this->load->database();
$this->load->model('report_model');
$this->load->helper('url');
$data['productionOrders'] = $this->report_model->getAllProductionOrders();
$this->load->view('all_reports', $data);
}
?>
Model
<?php
function getAllProductionOrders()
{
$this->db->select(*);
$this->db->from('dbo.QualityControl_ProductionOrders');
$query = $this->db->get();
return $query->result();
}
?>
View
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<?php
foreach ($productionOrdersas $row)
{
?>
<div>
ProdNo: <?php echo $row->Prodno; ?>
Descriptions:
Hours:
etc etc etc etc
</div>
[I want here comments and all user made notes]
<?php
}
?>
</body>
</html>