'Codeigniter - join value from two tables with same column name

i have two table which is riders and teams, and i like to show my data in my table, but the problem is both of those table have the same column name which is name, here for example :

Table riders

enter image description here

Table Teams

enter image description here

and here is the view in my table :

enter image description here

so what im trying to do is to join both table and make alias for the id_team, so that i can get the team name instead of their id_team, but since they had the same column name, i dont know how to do it, here is my model :

public function show()
{
    $this->db->select('team.id_team, team.name, rider.*', false);
    $this->db->from('teams as team');
    $this->db->join('riders as rider', 'team.id_team = rider.id_team');
    $query = $this->db->get();

    return $query->result();
}

here is my controller :

public function index()
{
  $data['riders_data'] = $this->riders->show();

  $this->load->view('back-end/template/header');
  $this->load->view('back-end/master-rider', $data);
  $this->load->view('back-end/template/footer');
}

and here is my table in my view :

<?php
$i = 1;
foreach($riders_data as $rider) {
?>
    <tr>
        <td><?php echo $i; ?></td>
        <td><img src="<?=base_url('/assets/riders/'.$rider->image); ?>" alt="" width="50px"></td>
        <td><?php echo $rider->name; ?></td>
        <td><?php echo $rider->number; ?></td>
        <td><?php echo $rider->country; ?></td>
        <td><?php echo $rider->id_team; ?></td> //team name
    </tr>
<?php
$i++;
}
?>

any help is really appreciated, thank you!.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source