<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$success = false;

$itemgrp = $_REQUEST["itemgrp"];

if ($itemgrp != "") {


    $query = "SELECT * FROM `product` WHERE `prodgrp`='$itemgrp' ORDER BY `code`";
    $result = mysqli_query($conn, $query)or die(mysqli_error($conn));
    

    if (mysqli_num_rows($result) > "0") {
        $success = true;
    }

    $rows = array();
    $ctr = 1;
    while ($r = mysqli_fetch_assoc($result)) {
        
        
        

        $rows[] = ['success' => $success,
            'ctr' => $ctr,
            'name' => $r[name],
            'barcode' => $r[barcode],
//            'gram' => $r[gram],
//            'packing' => $r[packing],
//            'colour' => $r[colour],
//            'unit' => $r[unit],
//            'gstperc' => $r[gstperc],
            'cost' => $r[cost],
            'rate' => $r[rate],
//            'mrp' => $r[mrp],
//            'msp' => $r[msp]
        ];
        $ctr++;
    }
    header("Content-type: application\json");
    echo json_encode($rows);
}