-1
I have a search script that scans up to three fields of a table called products, now I need to do a search in a table called brand, the product table has the id_brand that relates to the brand table, but I’m not able to implement.
The research is like this:
$pesquisa = $_REQUEST['s'];
$pesquisa = (strtolower($pesquisa));
// Agrupando campos no concat.
$campo = 'CONCAT(descricao, " ", resumo, " ", detalhes, " ", codigo_msb)';
// dividindo as palavras pelo espaço
$palavras = explode( " ", $pesquisa );
// eliminando ítens vazios
$palavras = array_filter($palavras);
// Inicializando a variável
$where = '';
$cola = 'WHERE ';
foreach ($palavras as $palavra) {
// Removendo espaços em branco
$palavra = trim($palavra);
$palavra = mysql_real_escape_string($palavra, $conexao);
$where .= $cola.$campo.' LIKE "%'.$palavra.'%" ';
$cola = 'AND ';
}
mysql_select_db($database_conexao, $conexao);
$query_rsBusca = "SELECT
produtos.id_marca,
marca.descricao AS marca
FROM
produtos
INNER JOIN marca ON (produtos.id_marca = marca.id_marca) ".$where." ";
$rsBusca = mysql_query($query_rsBusca, $conexao) or die(mysql_error());
$row_rsBusca = mysql_fetch_assoc($rsBusca);
$totalRows_rsBusca = mysql_num_rows($rsBusca);
The products table has the id_brand that relates to the brand table and need to do a search by brand name.
The error that is occurring is this:
Column 'descricao' in where clause is ambiguous
The question is about some PHP logic or about the SQL command? If it’s about SQL, you can make the question clearer by showing only the SQL code. Also, write down what you have tried so far and the problems encountered.
– Caffé
Hello @Caffe, yes, my question is about SQL, I’m doing a Join but the same is failing.
– adventistapr
Where is JOIN then? It doesn’t appear in the code you posted. And what do you mean by "it’s failing"? There’s an error?
– bfavaretto
I just updated the question with Join, but how do I use the Concat to search the fields in the products table without reference the table marks the error occurs.
– adventistapr