Selecting multiple fields from a table with a term in the query

Asked

Viewed 194 times

1

I tried to follow some steps I found here in the bad forum did not work...

I have this code here in the codeigniter model:

 // buscando clientes
     $this->db->like('nomeCliente',$termo);
     $this->db->limit(20);
     $data['clientes'] = $this->db->get('clientes')->result();

     // buscando os
     $this->db->like('idOs',$termo);
     $this->db->limit(20);
     $data['os'] = $this->db->get('os')->result();

     // buscando produtos
     $this->db->like('descricao',$termo);
     $this->db->limit(20);
     $data['produtos'] = $this->db->get('produtos')->result();

     //buscando serviços
     $this->db->like('nome',$termo);
     $this->db->limit(20);
     $data['servicos'] = $this->db->get('servicos')->result();

My question is this: in the clients table, I need you to do the research in other columns at the same time, as ptoref, cidadec through a term.

For example: The system user, looking for a name term "Dako", and he wants to know all the OS’s and customers that are related to "Dako", whether it be products he had tidied up, that he bought and etc.

I made some variations with the code above, in which I repeated the table block below clients, and just modified the column, so "theoretically" should find the client name and also ruac, etc.

I hope I explained my problem.

  • 1

    Just a caveat, this site is not a forum, it’s a Q&A

  • Sorry Diegofm, I was confused. But if you can help me in this matter, I thank you!

1 answer

0

Very simple Jardel.

Before performing a result(), you can increment as you imagine. Example:

$this->db->like('nomeCliente', $termo);
$this->db->like('nomeMae', $outroTermo);
$this->db->like('nomePai', $maisUmTermo);
$this->db->limit(20);
$data['clientes'] = $this->db->get('clientes')->result();
Who actually executes the query is the result()
  • thanks friend. I will test and anything I put here.

  • Friend... I did this that told me bad now does not research anything... it seems that it is not obeying the other tables.

  • Amigo Philipe Fernandes. I appreciate your help. To make it work, here I put the or_like in the other fields of the table. So it would be like in the first field, and in the other or_like. Now it’s perfect!

Browser other questions tagged

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