0
Guys I’m having a problem searching data in a table, follow code.
PHP CODE
<?php
$servidor = "localhost";
$usuario = "vitor";
$senha = "";
$banco = "funcionarios_db";
$mysqllink = mysqli_connect("$servidor","$usuario","$senha","$banco");
<?php
$parametro = filter_input(INPUT_GET, "parametro");
if($parametro){
$dados = mysqli_query("SELECT * FROM funcionario WHERE funcionario LIKE '%$parametro%' ORDER BY id_matricula");
}
else {
$dados = mysqli_query($mysqllink, "SELECT * FROM funcionario ORDER BY id_matricula");
}
$linha = mysqli_fetch_assoc($dados);
$total = mysqli_num_rows($dados); ?>
TABLE
<table border="1">
<tr>
<td>ID Matrícula</td>
<td>Funcionário</td>
<td>Cargo</td>
<td>Alocado</td>
</tr>
<?php
if($total){ do{
?>
<tr>
<td><?php echo $linha['ID Matrícula'] ?></td>
<td><?php echo $linha['Funcionário'] ?></td>
<td><?php echo $linha['Cargo'] ?></td>
<td><?php echo $linha['Alocado'] ?></td>
</tr>
<?php
} while($linha = mysqli_fetch_assoc($dados));
mysqli_free_result($dados);}
mysqli_close($mysqllink);
?>
People are returning this from my table:
Variable does not escape with single quotes only with double quotes, I think the mistake is this. Try replacing "SELECT * FROM funcio WHERE funcio LIKE '%$parametro%' ORDER BY id_matricula" by 'SELECT * FROM funcionario WHERE funcionario LIKE %". $parameter." % ORDER BY id_matricula'
– Vinicius De Jesus
Doing some kind of query in the database with GET parameter?
– Jefferson Ricardo
Vinicius didn’t work out
– João Lima
@Viniciusdejesus I believe that is not the problem, since the single quotes refer to the like parameter and the variable $parameter is inside double quotes.
– Gustavo Luciano
@Joãolima is having some mistake? if yes could inform which? Hugs.
– Gustavo Luciano
@Gustavo Luciano unfortunately no, he only creates the work with the table columns, and does not display the bank lines
– João Lima
How so just create table? table is no longer created?
– Vinicius De Jesus
@Vinicius de Jesus I did an EDIT in the post and put the table image.
– João Lima
normally use a for as a repetition structure to print data from a table, mainly because of the variable that makes the iteration be used as index of the array.
– Vinicius De Jesus
look at my answer down there and return to me.
– Vinicius De Jesus