<?php

  //setting header to json
  header('Content-Type: application/json');
  header("Access-Control-Allow-Origin: *");


  $id = $_POST["id"];  // get internal sensor id from js
  $driverID = $_POST["driver"];  // get value
  require '../php/database.php';


  $query = 'SELECT pinsAvailable.pinID, pinsAvailable.pinTypeID, pinsAvailable.portName, pinsAvailable.assigned, pinsAvailable.name, pinsAvailable.iconID, pinsType.pinTypeName, drivers.driverName
  FROM pinsAvailable
  LEFT JOIN pinsType
  ON pinsAvailable.pinTypeID = pinsType.pinTypeID
  LEFT JOIN drivers
  ON drivers.driverID = pinsAvailable.driverID
  WHERE pinsAvailable.driverID = '.$driverID.' AND gpio = '.$id.'';

  //query to get data from the table
  // $query = sprintf("SELECT `portName`, `name`, `pinTypeID` FROM `pinsAvailable` WHERE `gpio`='$id' AND `driverID`='$driverID'");

  //execute query
  $result = $mysqli->query($query);

  //loop through the returned data
  $dataWindow = array();
  foreach ($result as $row) {
    $dataWindow[] = $row;
  }

  //free memory associated with result
  $result->close();

  //close connection
  $mysqli->close();
  // print_r(json_encode($dataWindow));
  //now print the data
  print json_encode($dataWindow);