Retrieve column from a join in view

2

I have a query with join and in both tables I have a column with the same name ds_observacao .

The tables are: cliente and ordem_servico .

When showing in view , the value of this column returns me blank. You are looking for the column of the cliente table. How do I return the value to make explicit what I want from the ordem_servico table?

I have tried to do so in view :

echo $registros->ordem_servico->ds_observacao;

But without success.

    
asked by anonymous 03.02.2015 / 20:30

2 answers

2

I do not know CodeIgniter, but if you can change or write SQL directly try something like this:

SELECT 
  c.ds_observacao AS ds_observacao_cliente,
  os.ds_observacao AS ds_observacao_ordem_servico
FROM ordem_servico AS os
  JOIN cliente AS c ON (c.idCliente = os.idCliente)

In other words, using an alias to refer to the fields in the query itself so when it comes to retrieving the fields you will refer to the aliases and not the fields themselves.

    
03.02.2015 / 21:11
2

I was able to resolve using alias and specifying the columns in select .

$this->db->select ('e.id event_id, e.name event_name, v.id venue_id, v.name venue_name');
$this->db->join('venues v' , 'v.id = e.venue_id');
$query = $this ->db->get( 'events e');
    
03.02.2015 / 21:05