Welcome Guest, Not a member yet? Register   Sign In
Cross Reference Table
#2

[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>&lt;?php echo $athlete['last_name'].', '.$athlete['first_name']; ?&gt;</h2>
          &lt;?php echo $athlete['guardian_name']; ?&gt;<br/>
     &lt;?php else: ?&gt;
          &lt;?php echo $athlete['guardian_name']; ?&gt;<br/>
     &lt;?php endif; ?&gt;
&lt;?php endforeach; ?&gt;

Something like that anyways. I hope this helps.


Messages In This Thread
Cross Reference Table - by El Forum - 09-05-2010, 07:31 AM
Cross Reference Table - by El Forum - 09-05-2010, 10:17 AM
Cross Reference Table - by El Forum - 09-05-2010, 12:55 PM
Cross Reference Table - by El Forum - 09-05-2010, 01:08 PM
Cross Reference Table - by El Forum - 09-05-2010, 02:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB