-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_product_data.php
69 lines (59 loc) · 2.63 KB
/
fetch_product_data.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
include './include/check_login.php';
include './include/connection.php';
include_once 'include/admin-main.php';
// Check if stitcher and challan number are set
if (isset($_GET['stitcher']) && isset($_GET['challan'])) {
// Get the selected stitcher and challan number
$selectedStitcher = mysqli_real_escape_string($con, $_GET['stitcher']);
$selectedChallan = mysqli_real_escape_string($con, $_GET['challan']);
// Initialize arrays to store unique product combinations
$uniqueProducts = array();
// Fetch distinct product names, product bases, and product colors based on selected stitcher, challan number, and status = 0
$query = "SELECT DISTINCT product_name, product_base, product_color
FROM kits_job_work
WHERE stitcher_name = '$selectedStitcher'
AND challan_no_issue = '$selectedChallan'
AND status = 0";
$result = mysqli_query($con, $query);
// Fetch data and store unique product combinations
while ($row = mysqli_fetch_assoc($result)) {
// Construct a unique key for the product combination
$productKey = $row['product_name'] . '_' . $row['product_base'] . '_' . $row['product_color'] . '_';
// Check if the product combination already exists
if (!isset($uniqueProducts[$productKey])) {
// If not, add it to the array
$uniqueProducts[$productKey] = array(
'product_name' => $row['product_name'],
'product_base' => $row['product_base'],
'product_color' => $row['product_color']
);
}
}
// Prepare arrays for dropdown options
$productNames = array();
$productBases = array();
$productColors = array();
// Extract product names, product bases, and product colors from the unique product combinations
foreach ($uniqueProducts as $product) {
$productNames[] = $product['product_name'];
$productBases[] = $product['product_base'];
$productColors[] = $product['product_color'];
}
// Filter out duplicate product names and bases
$uniqueProductNames = array_unique($productNames);
$uniqueProductBases = array_unique($productBases);
$uniqueProductColors = array_unique($productColors);
// Prepare JSON response
$response = array(
'productNames' => $uniqueProductNames,
'productBases' => $uniqueProductBases,
'productColors' => $uniqueProductColors // Show only unique colors
);
// Send JSON response
echo json_encode($response);
} else {
// If stitcher or challan number is not set, return empty response
echo json_encode(array());
}
?>