How to Put Two Like in the same condition Mysql and PHP

0

I'm in the struggle of a system in php and mysql system sales etc ... it is all working, however accurate at the time of sale, the person can search for either (idCode or Description). without having two tabs of search. wanted to put two LIKE to search for (idCode, Description) would soon have an OR in the middle but not to achieve. Follow the Code Working with Search only with DESCRIPTION

public function autoCompleteProdutoSaida($q){

    $this->db->select('*');
    $this->db->limit(5);
    $this->db->like('descricao', $q);  "no caso aqui teria que ter um OR e um LIKE, porém não estou acertando."
    $this->db->where('saida',1);
    $query = $this->db->get('produtos');
    if($query->num_rows() > 0){
        foreach ($query->result_array() as $row){
            $row_set[] = array('label'=>$row['idCodigo']. ' | '.$row['descricao'].' | Preço: R$ '.$row['precoVenda'].' | Estoque: '.$row['estoque'],'estoque'=>$row['estoque'],'id'=>$row['idProdutos'],'preco'=>$row['precoVenda']);
        }
        echo json_encode($row_set);
    }
}
    
asked by anonymous 06.10.2018 / 19:38

1 answer

0

You should be using some framework as seen in your code. more independent of how you are going to implement can do some analysis before applying the query so as not to impact your system. Example if your code is just numeric, you can do an analysis

$ this- > db- > like ('description', $ q);

if (is_number) {    $ this- > db- > like ('code', $ q); }

Something like this will not need to apply a complexity to the query in the database thus leaving the process faster.

    
06.10.2018 / 21:40