<?php

require_once __DIR__ . '/db_config.php';

$r = array();
$r["spares"]= array();

if (isset($_POST["cname"]) ) {
 
$cname=$_POST["cname"];

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$query="SELECT item_name FROM spareparts WHERE companyname='$cname' GROUP BY item_name";
$result=mysqli_query($con,$query);

if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["spares"],$row["item_name"]);
    }
}

}

echo json_encode($r);

?>