[eluser]debow[/eluser]
I'm trying to display similar info from 3 tables into one. It's somewhat working but is only showing the last joined table not all 3. I'm not sure what is wrong at this point. Any suggestions are welcomed.
controller.php
Code:
function getevents() {
$data['detail'] = $this->exportexcel_model->getevents(); //call the model and save the result in $detail
$this->load->view('excel/test', $data);
}
model.php
Code:
function getevents() {
$this->db->select('*');
$this->db->from('100m_times');
$this->db->join('400m_times', '400m_times.name = 100m_times.name');
$this->db->join('mile_times', 'mile_times.name = 100m_times.name');
$this->db->join('swim_times', 'swim_times.name = 100m_times.name', 'left');
$getData = $this->db->get();
//$result= $getData->result_array();
//echo $result;
print_r($this->db->last_query());
if ($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
view.php
Code:
<h4>Score Sheet</h4>
<table border="1">
<?php if (count($detail) > 0) { ?>
<tr>
<th>ID</th>
<th>Name</th>
<th>Event</th>
</tr>
<?php
foreach ($detail as $rows) {
echo "<tr>";
echo "
<td>" . $rows['athlete_id'] . "</td>
<td>" . $rows['name'] . "</td>
<td>" . $rows['event'] . "</td>
";
}
?>
</table>
<?php } ?>
<br> <br>
<a href='export_excel/toExcelAll'><span style='color:green;'>Export All Data</span></a>
Current results
Code:
SELECT * FROM (`100m_times`) JOIN `400m_times` ON `400m_times`.`name` = `100m_times`.`name` JOIN `mile_times` ON `mile_times`.`name` = `100m_times`.`name` LEFT JOIN `swim_times` ON `swim_times`.`name` = `100m_times`.`name`
This is what I get outputed.
Score Sheet
ID Name Event
238 Dan Dudley 100m Swim
239 Tom Clancey 100m Swim
237 Mike Jones 100m Swim
What I want is this
Score Sheet
ID Name Event
238 Dan Dudley 100m Swim
239 Tom Clancey 100m Swim
237 Mike Jones 100m Swim
238 Dan Dudley 100m
239 Tom Clancey 100m
237 Mike Jones 100m
238 Dan Dudley 400m
239 Tom Clancey 400m
237 Mike Jones 400m