<?php

    header('Content-Type: application/json');
    header("Access-Control-Allow-Origin: *");
    
    $sort = $_GET["s"];  // get sort type

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

    //query to get data from the table
    $query = sprintf("SELECT `pinID`, `gpio`, `assigned`, `name`, `iconID`, `invert` FROM `pinsAvailable` WHERE `pinTypeID` = 2 AND `assigned` = 1 ORDER BY `{$sort}` ASC");

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

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

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

    //close connection
    $mysqli->close();