5
Hi, I’m running a search engine, but I’m kind of a layman when it comes to querys. The method I thought to refine the search, which in this case would be a simple search between two fields of a table with several products, was to go eliminating through selects.
$varBusca = str_replace(array(',',' ','.','%','-','/','\\'),'-',$_POST['busca']);
$varBusca = explode('-',$varBusca);
/* metodo 1 */
$query_busca="";
$pos_busca=0;
foreach($varBusca as $chave)
{
if ($pos_busca==0){
$query_busca.="SELECT * FROM ( # ) WHERE pro_nome LIKE '%$chave%' OR pro_descricao LIKE '%$chave%'";
}else{
$query_inserida="SELECT * FROM ( # ) WHERE pro_nome LIKE '%$chave%' OR pro_descricao LIKE '%$chave%'";
$query_busca=str_replace('#',$query_inserida,$query_busca);
}
$pos_busca++;
}
$query_busca=str_replace('#','produtos',$query_busca);
echo $query_busca;
I break the search string and search for every word. But this query ends up returning me no table item, even if there is some item with some query word.
Any suggestions?
Why do you wear the
( # )
? Wasn’t it easier to name the table in question? Besides, it seems to me querys are the same. I didn’t really understand what you mean by this code.– Jorge B.
@Jorgeb. apparently did not understand my code... I take the value of an input field (search box) and break to get the separate words. I want to take from the table only those items that contain all the words typed, regardless of the order... then put a select inside another select. I automatically add... but I’ve solved it. I’ve only had to use aliases. Name select as a temporary table.
– William Lima