-1
I have a code where you would have a select to select in which column you want to search and click on the letter to search within the selected column the selected letter.
The error is on my button. It would have to be a <a href="">
only that by having a <form action="">
directed to another page the href
conflicts with the form
Search code letter "A":
require_once 'functions.php';
$PDO = db_connect();
$opcao_filtro = filter_input(INPUT_POST, 'opcao_filtro', FILTER_SANITIZE_STRING);
$sql = 'SELECT * FROM tablet AS t WHERE';
//idlivro, titulo, tipo, e cor.
switch($opcao_filtro)
{
switch($opcao_filtro)
{
case 'titulo': {
$sql .= ' t.titulo like "a%"';
break;
}
case 'cor': {
$sql .= ' t.cor like "a%"';
break;
}
case 'categoria': {
$sql .= ' t.categoria like "a%"';
break;
}
}
$stmt = $PDO->prepare($sql);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$result = array_unique($rows);
foreach($rows as $row)
{
echo $row['titulo'];
echo $row['cor'];
echo $row['categoria'];
}
Button tag:
<button type="submit" class="btn btn-link btn-xs" value="a" name="a">A</button>
Select:
<div class="op">
<select name="opcao_filtro" class="form-control" style="width:150px; height:30px;">
<option value="nulo">---</option>
<option value="titulo">Título</option>
<option value="autor">Autor</option>
<option value="tema">Tema</option>
<option value="editora">Editora</option>
</select>
</div>
To know what is happening, you can give a
print_r($stmt->errorInfo())
shortly after the$stmt = $PDO->prepare($sql)
– adventistaam
Even so it returns blank.
– Emanoel
I realize you don’t have the method to execute:
$stmt->execute()
which would be shortly after the$stmt = $PDO->prepare($sql)
– adventistaam
I added it and it didn’t work :/
– Emanoel
Add these lines here at the beginning of the file and update to see
– adventistaam
Returned this error Uncaught Pdoexception: could not find driver in
– Emanoel