<?php

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

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

if ($_REQUEST["name"]) {


    $name = mysqli_real_escape_string($conn, $_REQUEST["name"]);

    $result = mysqli_query($conn, "SELECT  unit FROM  `item` WHERE `code`='$name'") or die(mysqli_error($conn));
    $tr = mysqli_fetch_array($result);
    $unitcode = $tr['unit'];
//    echo $rawcode;
    $mrn = mysqli_query($conn, "SELECT code,name FROM `unit` where `code` = '$unitcode'") or die(mysqli_error($conn));
    $trn = mysqli_fetch_array($mrn);
    $unitname = $trn['name'];

    $mown1 = mysqli_query($conn, "SELECT * FROM `unit` order by name") or die(mysqli_error($conn));
    echo "<option value='$unitcode'>$unitname</option>";
    while ($trow1 = mysqli_fetch_array($mown1)) {
        echo "<option value='$trow1[code]'>$trow1[name]</option>";
    }
}
?>
