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

Asked

Viewed 81 times

0

I am in the struggle of a system in php and mysql sales system etc.. it has everything working, but accurate at the time of sale, the person can search both for (idCodigo or Description). without having two search tabs. wanted to put Two LIKE to search by (idCodigo, Description) soon would have an OR in the middle but not getting it. Follow the Working Code with DESCRIPTION search only

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);
    }
}

1 answer

0

You must be using some framework as seen in your code. more independent of how you will implement can do some analysis before applying the query to not impact on your system. Example if your code is only numeric, you can do an analysis

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

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

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

  • I tried, I couldn’t, the idea would be that the employee was able to research the product, either by the barcode or by the product name. but I can only get him to research one or the other. until then how not to get. I had to make a page just for consultation, where he can put the name of the product. and find. and in the sale he only use the code. because in the bank. has the columns Description, idCodige.

  • I use here as I told you in some cases, another idea is to concatenate a column with the information and search for it using like. Concat(code,' ',description) Description, just an idea

Browser other questions tagged

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