-1
I am very confused.
I am creating an application with PHP and PDO. I have a page where there is a table with my database data. At first, it already makes the query in the bank and stores the result in $result
to popular my table:
<?php
session_start();
include('autenticacao/verifica.php');
include('class/DiagnosticoModel.php');
$consulta = new DiagnosticoModel();
$result = $consulta->select();
?>
My table:
<div class="card-body table-responsive">
<table class="table table-hover table-bordered">
<thead>
<tr class="table-cs">
<th>Ticket</th>
<th>Solicitante</th>
<th>Data Início</th>
<th>Data de entrega</th>
<th>Status</th>
<th>Observação</th>
<th>Ação</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($result as $chave => $valor) { ?>
<td><?php echo $valor['ticket'] ?></td>
<td><?php
if ($valor['data_inicio'] != 0) {
echo date("d/m/Y", strtotime($valor['data_inicio'])) ;
}
?></td>
<td>
<?php
if ($valor['data_termino'] != 0) {
echo date("d/m/Y", strtotime($valor['data_termino'])); }?></td>
<td><?php echo $valor['status'] ?></td>
<td style="width:300px"><?php echo $valor['observacao'] ?></td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-cs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-cogs"></i>
</button>
<div class="dropdown-menu">
<button name="btn-atualizar" class="dropdown-item" data-toggle="modal" data-target="#modal-atualizar<?echo $valor['iddiagnostico'];?>">Atualizar</button>
<div class="dropdown-divider"></div>
<button name="btn-visualizar" class="dropdown-item" data-toggle="modal" data-target="#modal-visualizar<?echo $valor['iddiagnostico'];?>">Visualizar Solicitação</button>
</div>
</div>
</td>
</tr>
So, I created 2 buttons, 1 to update and another to list data from the selected line. The buttons open modals with the information, and then to update, I make a new query to the bank, only it does not update the table at the same time, so I would like to use Ajax...
My question. I need to delete this initial part of PHP that makes the query and brings the data to the table? To do this with ajax? And if so, how can I do, since I’ve seen that you usually do so:
$.ajax({
url: 'index.php',
type: 'POST',
data: '<?php echo "teste"; ?>',
success: function(r) {
$('body').html(r);
}
});
(I got this code from the Internet) In this part of "DATA", are the data that I pass to do some research, some update, but since I have no parameter, I just want to request and receive the data, I need to fill this "date"? And do I need some other php helper page to put in the URL? Because I would like to do everything on that same page.
I don’t know if you can understand my doubt.
Thank you very much! It helped a lot, I will see the links. :)
– Alissonx