<?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];

if (isset($_REQUEST['brand'])) {
    $mbrand = $_REQUEST['brand'];
    $getbr = mysqli_query($conn, "SELECT code,name FROM `brand` WHERE `name`='$mbrand'") or die(mysqli_error($conn));
    $bcode = mysqli_fetch_array($getbr);
//    echo $bcode[code];

    $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `brand`='$bcode[code]'") or die(mysqli_error($conn));
    
       
    Echo "<option value=''></option>";
    while ($fitcd = mysqli_fetch_array($getitem)) {
        Echo "<option value='$fitcd[code]'>$fitcd[code]</option>";
    }
    
}

if (isset($_REQUEST['brandcode'])) {
    $brandcode = $_REQUEST['brandcode'];
    // $getbr = mysqli_query($conn, "SELECT code,name FROM `brand` WHERE `name`='$mbrand'") or die(mysqli_error($conn));
    // $bcode = mysqli_fetch_array($getbr);
//    echo $bcode[code];

    $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `brand`='$brandcode'") or die(mysqli_error($conn));
    
       
    Echo "<option value=''></option>";
    while ($fitcd = mysqli_fetch_array($getitem)) {
        Echo "<option value='$fitcd[code]'>$fitcd[code]</option>";
    }
    
}