How to retrieve variable value in a modal Bootstrap window

1

My problem is this: I have this code that displays multiple cars in a table:

<?php
$veiculos = "SELECT * from veiculo ";
$veiculos .= "WHERE id_secretaria = '1' ORDER BY placa DESC LIMIT 2"; //mudar conforme o id da secretaria
$query_veiculos = mysqli_query($conexao,$veiculos);
if(!$query_veiculos) {
die("Falha na consulta ao banco");
}
while ( $exibir = mysqli_fetch_array($query_veiculos)) {
$placa = $exibir["placa"];
?>
<li><a href="#" data-toggle="modal" data-target="#mostrar-veiculo" data-id='$placa' id="btnEditar"><?php  echo "Modelo: ".$exibir["modelo"]." | Placa: ".$placa." ";?><i class="ti-car pull-right"></i></a></li>
<?php } ?>

Clicking the link opens a modal with the following code:

<?php
include('../conecta-db.php');

$placa = $_POST["placa"];

$veiculos = "SELECT * from veiculo ";
$veiculos .= "WHERE placa = '{$placa}'";
$query_veiculos = mysqli_query($conexao,$veiculos);
if(!$query_veiculos) {
die("Falha na consulta ao banco");
}

?>


<!-- Modal -->
<div class="modal fade" id="mostrar-veiculo" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Veiculo selecionado</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
     <!--Lista com os cadastros-->
<div class="row">
  <div class="col-md-12">
  <div class="container">


  <table class="table table-responsive">
    <thead class="bg-primary">
      <tr style="color: #fff;">
        <th scope="col">#</th>
        <th scope="col">Placa</th>
        <th scope="col">Modelo</th>
        <th scope="col">Ano</th>
        <th scope="col">Km Rodados</th>
      </tr>
    </thead>
    <tbody>
      <?php $i = 1;?>

      <?php 
        while ( $exibir = mysqli_fetch_array($query_veiculos)) {
      ?>
      <tr>
        <th scope="row"><?php echo $i; ?></th>
        <td><?php echo $exibir["placa"]; ?></td>
        <td><?php echo $exibir["modelo"]; ?></td>
        <td><?php echo $exibir["ano"]; ?></td>
        <td><?php echo $exibir["km_rodados"]; ?></td>
      </tr>
    <?php $i++;} ?>
    </tbody>
  </table>
</div>
  </div>
</div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal" id="botao-fechar" style="width: 90%;
display: table;
margin-left: auto;
margin-right: auto;
position: static;">Fechar</button>
  </div>
</div>

I want to know how I can retrieve the value of the modal variable card to call only the line that has the same adapter in the database. follow system images:

Here are the links of the cars:

Hereisthemodalwhereyoushoulddisplayallthecarinformation:

    
asked by anonymous 22.06.2018 / 01:25

1 answer

0

You can do like me, it's kind of like a gambiarra, but it served me. It's just you put this code inside a function and call it by an onClick ().

$('#idDaModal').modal();
$("#idDoInput").val(variavalAqui);

Then you only create an input with type = hidden that will receive this value. I do not know if I understand correctly, but I hope I have helped.

    
22.06.2018 / 03:46