<?php
include "database/database.php"; // Include your database connection
include "database/data.php"; // Include your database connection

$user_name = 'ime_app';
$sql = "SELECT u.*, p.round_package_price, p.round_unit_price, p.round_pieces_price 
        FROM $user_1_ll u
        JOIN $product p ON u.product_name = p.product_name
        WHERE u.seller = '$user_name'";
$result = $connection->query($sql);

if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $price = match ($row['type']) {
            'ဖာ' => $row['round_package_price'],
            'ကဒ်' => $row['round_unit_price'],
            'ဗူး/ကဒ်' => $row['round_pieces_price'],
            default => 0
        };

        $total = $price * $row['qty'];

        $query1 = "UPDATE $user_1_ll SET price='$price', total='$total' WHERE tra_id='{$row['tra_id']}'";
        if (!$connection->query($query1)) {
            die("ERROR: Query failed. " . $connection->error);
        }

        $query2 = "UPDATE $sell_data SET price='$price', total='$total' WHERE tra_id='{$row['tra_id']}'";
        if (!$connection->query($query2)) {
            die("ERROR: Query failed. " . $connection->error);
        }
    }
} else {
    die("ERROR: Query failed. SQL: $sql - Error: " . $connection->error);
}

?>