[eluser]slowgary[/eluser]
Welcome to the CodeIgniter forums. Nice examples.
First, obviously, you need to get the data. I usually use active record, so in my model I'd have a function like so:
Code:
//model code
class Athletes_model extends Model
{
function get_all()
{
return $this->db
->join('xref_athgrd', 'xref_athgrd.athlete_id = athlete.id')
->join('guardians', 'guardians.id = xref_athgrd.guardian_id')
->order_by('athletes.last_name')
->order_by('athletes.first_name')
->get('athletes')
->result_array();
}
}
Then in your controller:
Code:
class Athletes extends Controller
{
function index() //this would be accessed by visiting http://www.yoursite.com/athletes/
{
$this->load->model('athletes_model', 'athletes');
$data['athletes'] = $this->athletes->get_all();
$this->load->view('athletes', $data);
}
}
Then your view:
Code:
// because MySQL returns denormalized data, you'll need to sift through each loop and check if the athlete is the same or new
<?php $temp = false; ?>
<?php foreach($athletes as $athlete): ?>
<?php if($temp != $athlete['athlete_id']): ?>
<?php $temp = $athlete['athlete_id']; ?>
<h2><?php echo $athlete['last_name'].', '.$athlete['first_name']; ?></h2>
<?php echo $athlete['guardian_name']; ?><br/>
<?php else: ?>
<?php echo $athlete['guardian_name']; ?><br/>
<?php endif; ?>
<?php endforeach; ?>
Something like that anyways. I hope this helps.