0
In the code visualize.php i do select no BD and I award a Table with the result of select and store in a variable $outworking. This variable is read by Javascript and written to .
I would like to change the code so that the Table layout is not in the $result variable, but in the modal body. That way I need Javascript to write the separate values in the modal.
Something like that:
$("#grid-tipo").html(id_tipo);
$("#grid-tipo").html(tipo);
$("#grid-tipo").html(status);
I tried to use a vector but was unsuccessful.
visualize.php
<?php
if(isset($_POST["id_tipo"])){
include_once "conexao.php";
$resultado = '';
$query_user = "SELECT * FROM tipos WHERE id_tipo = '" . $_POST["id_tipo"] . "' LIMIT 1";
$resultado_user = mysqli_query($conn, $query_user);
$row_user = mysqli_fetch_assoc($resultado_user);
$resultado .= '<dl class="row">';
$resultado .= '<dt class="col-sm-3">Código</dt>';
$resultado .= '<dd class="col-sm-9">'.$row_user['id_tipo'].'</dd>';
$resultado .= '<dt class="col-sm-3">Tipo</dt>';
$resultado .= '<dd class="col-sm-9">'.$row_user['tipo'].'</dd>';
$resultado .= '<dt class="col-sm-3">Status</dt>';
$resultado .= '<dd class="col-sm-9">'.$row_user['status'].'</dd>';
$resultado .= '</dl>';
echo $resultado;
}
?>
javascrip carrying the values
$(document).ready(function () {
$(document).on('click', '.view_data', function () {
var id_tipo = $(this).attr("id");
if (id_tipo !== '') {
var dados = {
id_tipo : id_tipo
};
$.post('visualizar.php', dados, function (retorna) {
$("#grid-tipo").html(retorna);
$('#viewParamTipos').modal('show');
});
}
});
});
modal code receiving values
<div id="viewParamTipos" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="viewParamTipos" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalLabel">Visualização de Tipos de Veículos</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Fechar"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<span id="grid-tipo"></span>
</div>
<div class="modal-footer">
<button class="btn btn-danger btn-sm" type="button" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
In your PHP file you can use json_encode to convert the array to JSON before sending the response. In your Javascript, just call the array. Here are a few examples: https://www.dyn-web.com/tutorials/php-js/json/array.php
– Bins