3
Good afternoon!
I have the following problem, I have to withdraw reports from a certain database where I should select specific employees, the same should be selected from a combobox:
<select name="usuario" id="usuario">
<option value="" disabled="disabled" selected="selected">Selecione o Usuário</option>
<option>funcionario 1</option>
<option>funcionario 2</option>
<option>funcionario 3</option>
</select>
I want that when selecting an employee, it is sent to the following query:
($result = $mysqli->query("SELECT * FROM tabela WHERE usuario='$funcionario';"))
Should I do this with json? early thanks.
Updating:
$(document).ready(function(){
$("#usuario").on("change", function(){
$.ajax({
url : 'sql.php',
type : 'POST',
cache : false,
dataType : 'json',
data : { 'usuario' : $("#usuario").val() },
error : function(){
alert('Erro ao tentar a ação!');
},
success : function( dados ){
console.log(dados);
}
});
});
});
<select name="usuario" id="usuario">
<option value="" disabled="disabled" selected="selected">Selecione o Usuário</option>
<option>funcionario 1</option>
<option>funcionario 2</option>
<option>funcionario 3</option>
</select>
`
and the SQL
:
$usuario = array("usuario" => array(array("codigo"=>"funcionario 1", "nome"=>"funcionario 1"), array("codigo" => "funcionario 2", "nome"=>"funcionario 2"), array("codigo"=>"funcionario 3","nome"=>"funcionario 3")));
echo json_encode($usuario);
if ($result = $mysqli->query("SELECT * FROM tabela WHERE usuario='$usuario';"))
{
// exibir os registros se há registros para mostrar
if ($result->num_rows > 0)
{
// exibir registros em uma tabela
echo "<table border='1' cellpadding='5' cellspacing=0 style=border-collapse: collapse bordercolor='#4B5AAB'>";
// definir cabeçalhos de tabela
echo "<tr> <th>ID</th> <th>Data</th> <th>Hora de entrada</th> <th>Hora de saída</th> <th>Comentário</th>";
while ($row = $result->fetch_object())
{
// cria uma linha para cada registro
echo "<tr>";
echo "<td>" . utf8_encode ($row->id) . "</td>";
echo "<td>" . utf8_encode ($row->data) . "</td>";
echo "<td>" . utf8_encode ($row->hora_entra) . "</td>";
echo "<td>" . utf8_encode ($row->hora_saida) . "</td>";
echo "<td>" . utf8_encode ($row->coment) . "</td>";
echo "</tr>";
}
echo "</table>";
You need to automatically search or change user. Or you will need to click a button to send?
– Randrade
Clicking a button, sending to another page probably.
– Thiago