3
Good night,
I have a research that contains multiple choices for checkbox
and Selects
and I’m trying to concatenate query
to search according to the user’s choice but I do not know what I may be doing wrong I will leave the code I currently have to see and if possible tell me what I may be doing wrong.
Code
$result_keywords = "";
if(isset($_GET['pesquisa'])){
$sql = "SELECT * FROM estabelecimentos WHERE keywords_pesquisa LIKE :keywords_pesquisa OR titulo LIKE :titulo AND activo = :activo ";
$result_keywords = $conexao->prepare($sql);
}
$checado = implode(",", $_POST['servicos']);
if(isset($_POST['servicos'])){
$sql .= "AND servicos = :servicos ";
$result_keywords = $conexao->prepare($sql);
}
if(isset($_GET['pesquisa'])){
$result_keywords->bindValue(':activo', 1, PDO::PARAM_INT);
$result_keywords->bindValue(':titulo', "%{$_GET['pesquisa']}%", PDO::PARAM_STR);
$result_keywords->bindValue(':keywords_pesquisa', "%{$_GET['pesquisa']}%", PDO::PARAM_STR);
}
if(isset($_POST['servicos'])){
$result_keywords->bindValue(':servicos', implode(",", $_POST['servicos']), PDO::PARAM_STR);
}
$result_keywords->execute();
$row_keywords = $result_keywords->fetchAll(PDO::FETCH_ASSOC);
Does an error appear? sql statement comes mounted wrong?
– rray
Now no error but does not present the results, the query is well mounted
– César Sousa
You can put a query here in the comments
– rray
I already managed to list it had some syntax errors only if selecting a chekbox if selecting two does not return me data
– César Sousa
For each value you need a placeholder(
:palceholder
) in consultation.– rray