Reputation: 147
I am running a query that returns 116 results. I am then attempting to loop those results through another query and display the results in a table. I just can't seem to get them all in the same table.
function average_battery_life_by_truck() {
$truck_num = $this->mhedash_model->select_truck();
$result = $truck_num->result_array();
foreach($result as $row){
$data = $this->_average_truck($row['truck_num']);
}
}
function _average_truck($array) {
$data[] = $array;
$query = $this->mhedash_model->select_battery_life_truck($array);
$result1 =& $query->result_array();
$this->table->set_heading('Average','Truck');
$data['table'] = $this->table->generate_table($result1);
$data['array2'] = $result1;
$data['main_content'] = 'mhe/average_truck_bat';
return $this->load->view('includes/template',$data);
}
////// VIEW
<?php foreach($array2 as $row): ?>
<TR >
<TD><?php echo $row['average_bat_life']; ?></TD>
<TD><?php echo $row['truck_num']; ?></TD>
</TR>
<?php $count++; ?>
Upvotes: 0
Views: 46
Reputation: 94652
This code will only give you the last result processed in the loop in $data
as you are over writing it each time
foreach($result as $row){
$data = $this->_average_truck($row['truck_num']);
}
Do this instead and you will get an array of results
foreach($result as $row){
$data[] = $this->_average_truck($row['truck_num']);
}
Upvotes: 1