<?php

$connect = new PDO("mysql:host=localhost;dbname=xml", "root", "");

if(isset($_POST["type"]))
{
 if($_POST["type"] == "category_id")
 {
  $query = "
  SELECT * FROM item 
  ORDER BY name ASC
  ";
  $statement = $connect->prepare($query);
  $statement->execute();
  $data = $statement->fetchAll();
  foreach($data as $row)
  {
   $output[] = array(
    'id'  => $row["model"],
    'name'  => $row["name"]
   );
  }
  echo json_encode($output);
 }
 else
 {
  $query = "
  SELECT product_category FROM item
  WHERE id = '".$_POST["category_id"]."' 
  ORDER BY name ASC
  ";
  $statement = $connect->prepare($query);
  $statement->execute();
  $data = $statement->fetchAll();
  foreach($data as $row)
  {
   $output[] = array(
    'id'  => $row["id"],
    'name'  => $row["product_category"]
   );
  }
  echo json_encode($output);
 }
}

?>