Abrir modal relativa ao id do pedido
Tenho a página pedidos.php, que recebe todos os pedidos que foram feitos no site nessa página tem informações com ID do pedido, ID do usuário, Endereço etc. Fiz um botão Produtos para que quando o ADM clique, abra uma modal vinda de outra página modalbox.php, com os produtos pedidos referentes aquele pedido. Por exemplo Pedido nº 833 ao lado dele terá um botão Produtos e quero que quando abrir a modal venha somente os produtos pedidos pelo 833. Com o código que tenho até o momento a modal abre, mas não mostra os produtos.
pedidos.php
<!--------------------------------
PEDIDOS ------------------------->
<div class="table-responsive mt-2">
<table class="table table-bordered table-striped text-center">
<thead>
<tr>
<td colspan="9">
<h4 class="text-center text-info m-0">Pedidos realizados</h4>
</td>
</tr>
<tr>
<th class="text-center">ID do pedido</th>
<th class="text-center">Nome do cliente</th>
<th class="text-center">E-mail</th>
<th class="text-center">Endereço</th>
<th class="text-center">Número da casa</th>
<th class="text-center">Valor</th>
<th class="text-center">ID cliente</th>
<th class="text-center">Situação</th>
<th class="text-center">Produtos</th>
</tr>
</thead>
<tbody>
<?php
require 'conexao_pedidos.php';
$stmt = $conn->prepare("SELECT * FROM orders");
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()):
?>
<tr>
<td>
<?= $row['order_id'] ?></td> <!-- ID do pedido -->
<td>
<?= $row['order_name'] ?></td>
</td>
<td><?= $row['order_email'] ?>
</td>
<td>
<?= $row['order_endereco'] ?>
</td>
<td>
<?= $row['order_numero'] ?>
</td>
<td>R$<?= $row['valor_total'] ?></td>
<td><?= $row['id_usuario'] ?> </td>
<!---- BOTÃO PARA ABRIR MODAL COM OS PRODUTOS ---->
<td>
<a class="btn btn-danger pull-right" data-toggle="modal" href="#myModal" id="modellink" data-client="<?= $row['order_id'] ?>">Produtos</a>
<div class="modal-container"></div>
<!----FIM BOTÃO PARA ABRIR MODAL COM OS PRODUTOS ---->
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<!----- JQUERY PARA ABRIR MODAL ----->
<script type="text/javascript">
$(document).ready(function(){
var order_id = $(this).attr("data-client");
var url = "modalbox.php?order_id=" + order_id;
$_post(url,{
order_id = order_id,
},
jQuery('#modellink').click(function(e) {
$('.modal-container').load(url,function(result){
$('#myModal').modal({show:true});
});
});
});
</script>
modalbox.php
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="table-responsive mt-2">
<table class="table table-bordered table-striped text-center">
<thead>
<tr>
<td colspan="8">
<h4 class="text-center text-info m-0">Produtos dos pedidos</h4>
</td>
</tr>
<tr>
<th>ID do pedido</th>
<th>ID cliente</th>
<th>ID produto</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
<?php
extract($order_id);
if (isset($_GET['order_id']))
{
$order_id = $_GET['order_id'];
}
else
{
die("ERRO: ID não definido.");
}
require 'conexao_pedidos.php';
$stmt = $conn->prepare("SELECT * FROM orders_items WHERE order_id = '$order_id'");
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()):
?>
<tr>
<td>
<?= $row['order_id'] ?>
</td>
<td>
<?= $row['id_usuario'] ?></td>
</td>
<td>
<?= $row['product_id'] ?>
</td>
<td>
<?= $row['quantity'] ?>
</td>
<!------- FIM ITEM REMOVER DO CARRINHO ------->
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>

Discussão (0)
Carregando comentários...