<?php
   session_start();

  
  include("../../db.php"); /* ESTABLISH CONNECTION IN THIS FILE; MAKE SURE THAT IT IS mysqli_* */
  
 
 $term=$_GET['term'];
 $column=$_GET['column'];
 $table=$_GET['table'];
 
 
 

 

  $stmt = $conn->prepare("SELECT  distinct `name` FROM `raw_material`   where `$column`  like '%$term%' ORDER BY IF(`$column` RLIKE '^[a-z]', 1, 2), `$column`
 "); /* START PREPARED STATEMENT */
 
 
 
  $stmt2 = $conn->prepare("SELECT  distinct `name` FROM `item`   where `$column`  like '%$term%' ORDER BY IF(`$column` RLIKE '^[a-z]', 1, 2), `$column`
 ");
 
 
 
 
  $stmt->execute(); /* EXECUTE THE QUERY */
  $stmt->bind_result($description); /* BIND THE RESULT TO THIS VARIABLE */
  while($stmt->fetch()){ /* FETCH ALL RESULTS */
    $description_arr[] = $description; /* STORE EACH RESULT TO THIS VARIABLE IN ARRAY */
  } /* END OF WHILE LOOP */

  
  $stmt2->execute(); /* EXECUTE THE QUERY */
  $stmt2->bind_result($description2); /* BIND THE RESULT TO THIS VARIABLE */
  while($stmt2->fetch()){ /* FETCH ALL RESULTS */
    $description_arr[] = $description2; /* STORE EACH RESULT TO THIS VARIABLE IN ARRAY */
  } 
  
  
  echo json_encode($description_arr); /* ECHO ALL THE RESULTS */
  

 
?>