<?php

    require '../php/database.php';

//  get driver ID from drop down box so we only load pins related
    $the_id = intval($_POST['id']);

    $query = 'SELECT pinsAvailable.pinID, pinsAvailable.driverID, pinsAvailable.gpio, pinsAvailable.portName, pinsAvailable.assigned, pinsAvailable.pinTypeID, pinsAvailable.name, pinsAvailable.iconID, pinsAvailable.invert, pinsType.pinTypeName, drivers.driverName
        FROM pinsAvailable
        LEFT JOIN pinsType
        ON pinsAvailable.pinTypeID = pinsType.pinTypeID
        LEFT JOIN drivers
        ON drivers.driverID = pinsAvailable.driverID
        ORDER BY pinsAvailable.pinID ASC';
        // ORDER BY pinsAvailable.driverID ASC, pinsAvailable.gpio ASC';
        // WHERE pinsAvailable.driverID = '.$the_id.'';


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

    //loop through the returned data and place in variable to send back to frontend
    $dataWindow = array();
    foreach ($result as $row) {
        $dataWindow[] = $row;
    }

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

    print json_encode($dataWindow);
?>