<?php
// Function to fetch user name based on uid
function fetchUserName($con, $uid) {
    $sql = "SELECT uname FROM users WHERE uid = '" . mysqli_real_escape_string($con, $uid) . "'";
    $run = mysqli_query($con, $sql);
    if ($row = mysqli_fetch_assoc($run)) {
        return $row["uname"];
    }
    return '';
}

// Function to fetch service details for a specific product
function fetchServiceDetails($con, $productId) {
    $sql = "SELECT * FROM data WHERE data_catagory = 'service' AND data_sl_no = '{$productId}'";
    $run = mysqli_query($con, $sql);
    if ($row = mysqli_fetch_assoc($run)) {
        return [
            'product' => $row["data_title"],
            'pricing' => $row["data_seo_tag"]
        ];
    }
    return ['product' => '', 'pricing' => ''];
}

// Function to fetch total payment for a product
function fetchTotalPayment($con, $productId) {
    $sql = "SELECT SUM(payment) AS total_payment FROM payment WHERE p_forProduct = '" . mysqli_real_escape_string($con, $productId) . "'";
    $run = mysqli_query($con, $sql);
    if ($row = mysqli_fetch_assoc($run)) {
        return !is_null($row['total_payment']) ? $row['total_payment'] : 0;
    }
    return 0;
}

// Function to fetch category name based on category id
function fetchCategoryName($con, $categoryId) {
    $sql = "SELECT cname FROM category WHERE cid = '{$categoryId}'";
    $run = mysqli_query($con, $sql);
    if ($row = mysqli_fetch_assoc($run)) {
        return $row["cname"];
    }
    return '';
}

?>