Recover column of a Join in view

Asked

Viewed 215 times

2

I have an appointment with Join and in both tables I have a column with the same name ds_observacao.

The tables are: cliente and ordem_servico.

Time to show on view, the value of this column returns me blank. Because it is searching the table column cliente. How do I return the value to make explicit what I want from the table ordem_servico?

I’ve tried to do that view:

echo $registros->ordem_servico->ds_observacao;

But to no avail.

  • Good afternoon, did you manage to solve your problem with any of the answers? If yes, please indicate which one marks the "V" just below the question’s rating. If you don’t let us know your progress so we can continue to help you.

2 answers

2

I managed to solve using alias and specifying the columns in the 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');

2

I don’t know Codeigniter, but if you can change or write SQL directly try something similar to 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)

That is to use an alias to refer to the fields in the query itself so when retrieving the fields you will refer to the alias and not the fields themselves.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.