6
I have a page with a table whose code field is a link that opens a modal. I need that when opening the modal, show another table, only with the data according to the value of the field (code) clicked. How do I receive within the modal the value of the chosen field ?
Someone knows how to do it ?
Code:
<table class="table table-bordered table-hover center-text" name="carrtab" id="carrtab"
style="background-color: #ffffff;">
<thead align="center">
<tr class="danger">
<th class="text-center">Data</th>
<th class="text-center">Tipo</th>
<th class="text-center">Descrição</th>
<th class="text-center">Cliente</th>
<th class="text-center">Usuario</th>
<th class="text-center">Link</th>
</tr>
</thead>
<tbody>
<?
$tipoentradalog = post('tipoentradalog');
$usuario = post('usuario');
$codcliente = post('codcliente');
$datade = post('datade');
$dataate = post('dataate');
$codigo = post('codigo');
$sql = "select
l.datacriacao,
tl.nome as tipo,
l.descricao,
cli.nome as cliente,
us.nome as usuario,
l.codigo
from log l
inner join cliente cli on cli.codcliente=l.codcliente
inner join usuario us on us.codusuario=l.codusuario
inner join empresa emp on emp.codempresa=l.codempresa
inner join tipoentradalog tl on tl.codtipoentradalog=l.codtipoentradalog
where cli.codempresa=$codempresa
and l.datacriacao between '$datade%' and '$dataate%' ";
if($usuario != ""){
$sql .= " and us.codusuario=$usuario ";
}
if($codcliente != "") {
$sql .= " and cli.codcliente=$codcliente ";
}
if($tipoentradalog != "") {
$sql .= " and tl.codtipoentradalog=$tipoentradalog ";
}
$rst = my_query($connR, $sql);
foreach($rst as &$row){
?>
<tr>
<td align="center"><?=normalDate($row['datacriacao']);?></td>
<td align="center"><?=$row['tipo']?></td>
<td align="center"><?=$row['descricao']?></td>
<td align="center"><?=$row['cliente']?></td>
<td align="center"><?=$row['usuario']?></td>
<td align="center"><a class="link-target" role="link" data-toggle="modal" href="#modalContainer" aria-expanded="false" aria-controls="modalContainer" style="text-decoration: none; color: black;"><?=$row['codigo']?></a></td>
</tr>
<?
if($row['codigo'] != "")
{
global $codigo;
$codigo = $row['codigo'];
}
}?>
</tbody>
</table>
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="myModalLabel">Extrato Rodízio</h3>
</div>
<div class="modal-body">
<h4>Chat</h4>
<table name="tabrod" id="tabrod" class="table table-bordered table-hover center-text" style="background-color: #ffffff;">
<thead align="center">
<tr class="danger">
<th class="text-center">Data</th>
<th class="text-center">Cliente</th>
<th class="text-center">Usuario</th>
</tr>
</thead>
<tbody>
<?
$sql = "select cli.codcliente, cli.nome, emp.nome as empresa from cliente cli
inner join empresa emp on emp.codempresa=cli.codempresa
where cli.codcliente=$codigo;";
$rst = my_query($connR, $sql);
foreach ($rst as $row) {
?>
<tr>
<td align="center"><?= $row['codcliente']; ?></td>
<td align="center"><?= $row['nome'] ?></td>
<td align="center"><?= $row['empresa'] ?></td>
</tr>
<?
}?>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
To do this the content of your Modal must be external, and you must do something similar to this answer.
– KaduAmaral
Hi Kadu, thanks for your help. So... you didn’t roll in mine. I was a little confused because I did not identify in the code a value corresponding to 'Idcodprodutos' in the example you showed me. Is there any way you could just explain to me what I should do? Thank you.
– goldenleticia
In your case I believe it is the variable
$row['codigo']
, but your code is a bit confused, I don’t think you have a good logic. And all the code that is inside themodal-content
should be a separate page, which should be sent the variable$row['codigo']
to load your SQL with the data you want.– KaduAmaral
I understood this part of a separate page for modal... I’ll try again. Thank you
– goldenleticia
Donna added an answer, read it over and try to do as I did. Since I haven’t tried it, there may be some errors, do some tests. Anything leave a comment on the reply. Another thing I noticed in your code, is that you use the short tag
<?
, just be careful, because some servers have them disabled, always give preference to<?php
.– KaduAmaral