I'm starting with codeigniter and I have a trouble with a DB query. If I run the query in a standard PHP code, it show all data passed in the query but if I run the query using codeigniter, it show only one row with a foreach.
In the Model:
$query = $this->db->query('select C.display_name AS "Servicio", B.output AS "Status", B.last_time_ok AS "Ultimo OK" , B.last_time_critical AS "Ultimo Critical"
from system_hosts AS A
INNER JOIN system_services AS C ON C.host_object_id = A.host_object_id
INNER JOIN system_servicestatus AS B ON B.service_object_id = C.service_object_id
WHERE A.alias = "'.$hostname.'" GROUP BY C.display_name;');
return $query->row_array();
In the view:
<?php foreach ($hosts_service as $services):
?> <tr>
<h2><td><?php echo $hosts_service['Servicio'] ?></a></td></h2>
<h2><td><?php echo $hosts_service['Status'] ?></a></td></h2>
<h2><td><?php echo $hosts_service['Ultimo OK'] ?></a></td></h2>
<h2><td><?php echo $hosts_service['Ultimo Critical'] ?></a></td></h2> </tr>
<?php endforeach ?>
In Controller:
$data['hosts_service'] = $this->news_model->get_service($hostname);
It return the same value 4 times, but if I run in normal PHP it return the 3 different values containing in the DB, so the query is correct. (I tried the same query in Toad and the result are OK).
What can be the problem?