Problems showing related data in Codeigniter

1

It turns out that I have a problem I want to show the name of tables related to inner join in Codeigniter but it does not let me not know what I'm doing wrong.

Controller

public function consulta() {
    $asociados = array("tablaAsociados" => $this->asociados_modelo->listarAsociados());
    $this->load->view( 'consulta', $asociados );
}

Model

//consultamos los datos de asociados y mostraremos en tabla con datos relacionados
public function listarAsociados() {
    $this->db->order_by( 'id_asociado', 'asc' );
    $this->db->select('*');
    $this->db->join('paises', 'paises.code = asociados.pais');
    $query = $this->db->get( 'asociados' );
    return $query->result_array();
}

Vista

<?php foreach ($tablaAsociados as $tabla):?>
    <td><?php echo $tabla['nombre_primero'];?></td>
    <td><?php echo $tabla['apellido_primero'];?></td>
    <td><?php echo $tabla['dui'];?></td>
    <td><?php echo $tabla['nit'];?></td>
    <td><?php echo $tabla['municipio'];?></td>
    <td><?php echo $tabla['departamento'];?></td>
    <td><?php echo $tabla['pais'];?></td>
    </tr>
<?php endforeach;?>

But it does not show me the name of the whole country only the id value of the country, in the same way I want to show the municipality and related department.

People Listing Capture
Thank you in advance for your help.

    
asked by Edwin Vasquez 03.08.2018 в 05:21
source

2 answers

0

You're doing it in a weird way, that's how it should work:

public function listarAsociados()
{
   $this->db->select('a.*,p.*');
   $this->db->from('asociados a');
   $this->db->join('paises p', 'p.code = a.pais');
   $this->db->order_by( 'a.id_asociado', 'asc' );
   $query = $this->db->get();
   return $query->result_array();
}

I'm going to call all the parameters of both tables because I do not know exactly what you need.

    
answered by 03.08.2018 / 06:29
source
0

Hello Here I leave a provada proposal would be to review how is the integrity of your data.

Model

public function listarAsociados(){
        $query = $this->db->query("SELECT a.*,p.nombrepais as pais FROM asociados a INNER JOIN pais p ON a.idpais=p.id ORDER BY a.id ASC");
        return $query->result();
    }
    
answered by 09.08.2018 в 05:41