File size: 1,179 Bytes
7845020
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
header("Content-Type: application/json");
include "db.php";

// Get menu items with stock and popularity (order count)
$sql = "SELECT f.*, 
        COALESCE(s.quantity, 0) as stock,
        COALESCE(pop.total_qty, 0) as popularity
        FROM foods f
        LEFT JOIN stock s ON f.id = s.food_id
        LEFT JOIN (
            SELECT food_id, SUM(quantity) as total_qty
            FROM order_items
            GROUP BY food_id
        ) pop ON f.id = pop.food_id
        ORDER BY popularity DESC";
$stmt = $conn->query($sql);

$menu = [];
while ($row = $stmt->fetch()) {
    $row['id'] = (int)$row['id'];
    $row['price'] = (float)$row['price'];
    $row['stock'] = (int)$row['stock'];
    $row['popularity'] = (int)$row['popularity'];
    $cat_emojis = [
        'Beverages' => 'πŸ₯€',
        'Wafers' => 'πŸͺ',
        'Snacks' => '🍟',
        'Coffee & Drinks' => 'β˜•',
        'Hot Dogs' => '🌭',
        'Biryani' => 'πŸ›'
    ];
    $row['emoji'] = $cat_emojis[$row['category']] ?? '🍽';
    $row['cat'] = $row['category'];
    $row['img'] = $row['image_url'];
    $row['sub'] = $row['description'];
    $menu[] = $row;
}

echo json_encode($menu);
?>