0
Hello, How do I use a single input text to query 2 columns? Currently my code has an input=select and an input=text but in the text I want to see 2 columns.. how do I do this in the sql query? Note that in my input=text in the placeholder I want to search by the "OK" number or "Description" of the item.. Someone gives me a light?
$query = ("SELECT bem, des_bem, revenda FROM AFX_BEM WHERE revenda LIKE :rev AND des_bem LIKE :bd ");
$stmt = $pdo->prepare($query);
$stmt->bindValue(':rev', '%' . $var1 . '%', PDO::PARAM_STR);
$stmt->bindValue(':bd', '%' . $var2 . '%', PDO::PARAM_STR);
$stmt->execute();
html
<form class="form-inline" role="form" action="lista.php" method="get">
<div class="form-group">
<label for="revenda">Pesquisar</label>
<select class="form-control" name="revenda" style="width: 140px" onchange="this.form.submit();" >
<option value="<?php echo $_GET["revenda"]
?>" selected><?php if(isset($_GET["revenda"]) ) {
if ( ($_GET["revenda"]) == 1 ) { echo "Piracicaba"; }
if ( ($_GET["revenda"]) == 2 ) { echo "Botucatu"; }
if ( ($_GET["revenda"]) == 3 ) { echo "São Manuel"; }
if ( ($_GET["revenda"]) == 4 ) { echo "Lençóis Paulista"; }
if ( ($_GET["revenda"]) == 5 ) { echo "Jaú"; }
if ( ($_GET["revenda"]) == 6 ) { echo "Ibitinga"; }
} else { ?>Revenda <?php } ?></option>
<?php
$linha2 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
foreach($linha2 as $listar2){
?>
<option value="<?php echo $listar2["REVENDA"]; ?>">
<?php echo utf8_encode($listar2["RAZAO_SOCIAL"]); ?>
</option>
<?php
}
?>
</select>
<input class="form-control" type="text" name="bemdesc" id="bemdesc" placeholder="BEM ou Descrição" <?php if(!isset($_GET["revenda"]) ) { ?> hidden <?php } ?> >
<button class="btn btn-default" type="submit" <?php if(!isset($_GET["revenda"]) ) { ?> hidden <?php } ?>><i class="fa fa-search"></i></button>
I had tried to do this.. but then my query returns nothing
– Fernando Fefu
I understood your question, adjusted the query, try again now.
– André Lins
not even return. but I did the same query in the database placing the parameters manually and returned normal values.. I believe the problem is now in the treatment of the parameters in PDO.. I may be using the same bindvalue 2 times?
– Fernando Fefu
I got it this way. I don’t know if it’s the right one but it worked:
– Fernando Fefu
Maybe a solution is to put 3 parameters, give a look at the new query.
– André Lins