Untitled
unknown
plain_text
a year ago
4.0 kB
7
Indexable
<h2>Pasūtījumi</h2> <?php if (!(isset($_GET['page']) && $_GET['page'] === 'orders' && isset($_GET['id']))) { // Fetch orders from database $sql = "SELECT id, user_id, order_date, total_amount, status FROM orders ORDER BY order_date DESC"; $result = $conn->query($sql); // Check if there are any orders if ($result->num_rows > 0) { echo "<table class='table'>"; echo "<thead><tr><th>Pasūtījuma numurs</th><th>Lietotāja ID</th><th>Pasūtījuma datums</th><th>Kopējā summa</th><th>Statuss</th></tr></thead>"; echo "<tbody>"; // Display each order as a row in the table while ($row = $result->fetch_assoc()) { $orderId = $row['id']; $userId = $row['user_id']; $orderDate = $row['order_date']; $totalAmount = $row['total_amount']; $status = $row['status']; echo "<tr>"; echo "<td><a href='?page=orders&id=$orderId'>$orderId</a></td>"; echo "<td>$userId</td>"; echo "<td>$orderDate</td>"; echo "<td>$totalAmount EUR</td>"; echo "<td>$status</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; } else { echo "<p>Nav pieejamu pasūtījumu.</p>"; } } // If specific order details are requested else { $orderId = $_GET['id']; // Fetch order details from orders table $sql_order = "SELECT * FROM orders WHERE id = ?"; $stmt_order = $conn->prepare($sql_order); $stmt_order->bind_param("i", $orderId); $stmt_order->execute(); $result_order = $stmt_order->get_result(); if ($result_order->num_rows == 1) { $order = $result_order->fetch_assoc(); $userId = $order['user_id']; $orderDate = $order['order_date']; $totalAmount = $order['total_amount']; $status = $order['status']; echo "<h2>Pasūtījuma detaļas</h2>"; echo "<p><strong>Pasūtījuma numurs:</strong> $orderId</p>"; echo "<p><strong>Lietotāja ID:</strong> $userId</p>"; echo "<p><strong>Pasūtījuma datums:</strong> $orderDate</p>"; echo "<p><strong>Kopējā summa:</strong> $totalAmount EUR</p>"; echo "<p><strong>Statuss:</strong> $status</p>"; // Fetch products associated with the order from order_products table $sql_products = "SELECT op.quantity, op.price, p.name, p.photo FROM order_products op JOIN products p ON op.product_id = p.id WHERE op.order_id = ?"; $stmt_products = $conn->prepare($sql_products); $stmt_products->bind_param("i", $orderId); $stmt_products->execute(); $result_products = $stmt_products->get_result(); if ($result_products->num_rows > 0) { echo "<h3>Pasūtīto produktu saraksts:</h3>"; echo "<table class='table'>"; echo "<thead><tr><th>Attēls</th><th>Nosaukums</th><th>Cena</th><th>Daudzums</th><th>Kopā</th></tr></thead>"; echo "<tbody>"; while ($product = $result_products->fetch_assoc()) { $productName = $product['name']; $productPhoto = $product['photo']; $productPrice = $product['price']; $productQuantity = $product['quantity']; $productTotal = $productPrice * $productQuantity; echo "<tr>"; echo "<td><img src='../$productPhoto' alt='$productName' style='max-width: 100px;'></td>"; echo "<td>$productName</td>"; echo "<td>$productPrice EUR</td>"; echo "<td>$productQuantity</td>"; echo "<td>$productTotal EUR</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; } else { echo "<p>Šim pasūtījumam nav saistītu produktu.</p>"; } } else { echo "<p>Pasūtījums ar šādu numuru nav atrasts.</p>"; } } ?>
Editor is loading...
Leave a Comment