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

$itemname = $_REQUEST['itemname'];

$cond = "";
if (!empty($itemname)) {
    $cond = " AND `name` LIKE '%$itemname%'";
}

$query = "SELECT `code`,`name`,`cost`,`rate`,`opening`,`minimum` FROM `item` WHERE `code`!='' $cond ORDER BY `name`";

$result = mysqli_query($conn, $query)or die(mysqli_error($conn));

$rows = array();
$ctr = 0;
while ($r = mysqli_fetch_object($result)) {
    $rows[] = [ 'success' => true,
                'ctr' => $ctr,
                'code' => $r[code],
                'name' => $r[name],
                'cost' => $r[cost],
                'rate' => $r[rate],
                'opening' => $r[opening],
                'minimum' => $r[minimum]
    ];
    $ctr++;
}
header("Content-type: application\json");
echo json_encode($rows);

