1
I do the search with the existing numMec and appears to me that does not exist in the database
<?php
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9]#i","",$searchq);
$query = mysql_query("SELECT * FROM bombeiros WHERE numMec = '%$searchq%'") or die("Nao consegue pesquisar");
$count = mysql_num_rows($query);
if($count==0){
$output='<div class="alert alert-warning alert-dismissable fade-in">
<a class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Bombeiro</strong> não existe na base de dados.
</div>';
}else{
$nome=$row_bombs['Nome'];
$num=$row_bombs['numMec'];
while($row = mysql_fetch_array($query)){
$output='<div class="col-sm mx-auto" style="padding-top: 20px;">
<div class="card" style="width: 300px;">
<img class="mx-auto card-img-top" src="img/BVMCN.png" style="width: 50%; padding-top: 10px;"></br>
<div class="card-body">
<h5 class="card-title"> '.$nome.'</h5>
<a href="bombeiro.php?id="'.$num.' class="btn btn-primary col-sm">'.$num.'</a>
</div>
</div>
</div>';
}
}
}
?>
<?php print("$output");?>
and this at the end of me an error(Notice: Undefined variable: output)
Because you put
numMec = '%$searchq%'"
, instead of equal would not be like? Probably your query is wrong.– Max Rogério
but I want it to be the same result and not like
– Adelino Vasconcelos
because if I put like does not appear the number I searched but another
– Adelino Vasconcelos
What comes in
$_POST['search']
? What kind ofnumMec
on the tablebombeiros
?– Isac
are numbers in all 8 and this as int
– Adelino Vasconcelos
So that the symbol of percentage will not be searched using the
like
? In doingnumMec = '%$searchq%'
, you’re making sql understandnumMec = '%12345678%'
, so it won’t bring any results. Or remove the%
or use thelike
instead of=
– Max Rogério