<?php

//setting header to json 

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

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

    //query to get data from the table
    // $query = sprintf("SELECT timestamp, temp1, temp2, temp3, temp4, temp5 FROM data");

    $query = 'SELECT stirrers.stirrerID, stirrers.stirrerPinID, pinsAvailable.name
        FROM stirrers
        LEFT JOIN pinsAvailable
        ON pinsAvailable.pinID = stirrers.stirrerPinID
        ORDER BY stirrers.stirrerID ASC';

    //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_r(json_encode($dataWindow));
    //now print the data
    print json_encode($dataWindow);