<?php
include(__DIR__ . '/../config.php');

$id = $_GET['id'];

$stmt = $pdo->prepare("SELECT * FROM order_items WHERE order_id=?");
$stmt->execute([$id]);
$items = $stmt->fetchAll();
?>

<h2>Order Details</h2>

<table border="1" cellpadding="10">
<tr>
<th>Product</th>
<th>Qty</th>
<th>Price</th>
</tr>

<?php foreach($items as $item):

$stmt = $pdo->prepare("SELECT name FROM products WHERE id=?");
$stmt->execute([$item['product_id']]);
$p = $stmt->fetch();
?>

<tr>
<td><?= $p['name']; ?></td>
<td><?= $item['quantity']; ?></td>
<td><?= $item['price']; ?></td>
</tr>

<?php endforeach; ?>
</table>