shubraVeil/api/products.php

31 lines
730 B
PHP
Raw Normal View History

2024-12-25 13:05:50 +02:00
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
require_once '../admin/config/database.php';
$type = isset($_GET['type']) ? mysqli_real_escape_string($conn, $_GET['type']) : null;
$sql = "SELECT * FROM products";
if ($type) {
$sql .= " WHERE product_type = '$type'";
}
$sql .= " ORDER BY created_at DESC";
$result = mysqli_query($conn, $sql);
$products = [];
while ($row = mysqli_fetch_assoc($result)) {
$products[] = [
'id' => $row['id'],
'name' => $row['name'],
'description' => $row['description'],
'price' => $row['price'],
'image' => $row['image'],
'category' => $row['category']
];
}
echo json_encode($products);
?>