0
I would like to know how to make a dynamic data filter, to appear only the data related to the selected, for example:
I have in my bank the table Empregado
and Empresa
, as an example I have:
- Staff 1(fk_company 1), Works at Company 1;
- Employee 2(fk_company 1), Works at Company 1;
- Employee 3(fk_company 2), Works at Company 2;
- Employee 4(fk_company 2), Works at Company 2;
So when I clicked on Combobox, and selected Company 1 I wanted only employees 1 and 2 to appear, on the combobox below. But now I would like to know how to do, probably should be in AJAX, but AJAX I do not know much so I ask for help to you.
Code of Comboboxes:
Enterprise:
<div class="profile-info-row">
<div class="profile-info-name"> **Empresa** </div>
<div class="profile-info-value">
<select name="empresa_destino" id="form-field-1" class="col-xs-11 col-sm-6 col-md-8">
<option value="" selected disabled="disabled" hidden>Selecione a Empresa</option>
<?php $line = $searchSQL->fetchAll(PDO::FETCH_ASSOC);
foreach($line as $thread):?>
<option value="<?php echo $thread['cod_empresa']; ?>"><?php echo $thread['razao_social']; ?></option> <?php endforeach; ?>
</select>
</div>
</div>
Employee:
<div class="profile-info-row">
<div class="profile-info-name"> Nome do Empregado </div>
<div class="profile-info-value">
<select name="empregado" id="form-field-1" class="col-xs-11 col-sm-6 col-md-8">
<option value="" selected disabled="disabled" hidden>Selecione o Empregado</option>
<?php
$plataform = $requestSQL->fetchAll(PDO::FETCH_ASSOC);
foreach($plataform as $contour): ?>
<option value="<?php echo $contour['cod_empregado']; ?>"><?php echo $contour['nome']; ?></option> <?php endforeach; ?>
</select>
</div>
</div>
EDIT
According to suggestions I remade some parts, and although the company ID is caught (proven by Alert), it is not returning anything, why? Follow the file for viewing
filterEmp file:
<?php
require 'conexao.php';
$pdo = conectar();
if (isset($_POST['id_empresa'])) :
try{
$cod_empresa = $_POST['id_empresa'];
$SQL = "SELECT * FROM tbl_empregado WHERE fk_empresa = ?";
$stmt = $pdo->prepare( $SQL );
$stmt->bindValue(1, $cod_empresa, PDO::PARAM_INT);
$stmt->execute();
$row=$stmt->fetch(PDO::FETCH_ASSOC);
extract($row);
}catch(PDOException $e){
'ERROR :' . $e->getMessage()."<br>";
'ERROR :' . $e->getCode();
}endif;
?>
Hello @Vanildo I made the changes but when there is the change nothing occurs, exactly as it would be my file in PHP for query
– UzumakiArtanis
I updated the post
– UzumakiArtanis
I forgot to add the method in the ajax request. See how it is now, and if it works
– Vanildo Souto Mangueira
Still nothing has happened
– UzumakiArtanis
In the query file you should return the entire HTML, with the Divs and select already ready.
– Vanildo Souto Mangueira
I did this post a while ago on my blog, more or less what you want to do: http://blog.toneladas.com.br/respondendo-no-stackoverflow-1.html
– Vanildo Souto Mangueira
Okay now I understand I’m going to try to develop something here and then I show you an answer
– UzumakiArtanis