<?php
// Read the JSON data from the file
$data = file_get_contents('RTXPlalist.json');

// Parse the JSON data into an array of rows
$rows = json_decode($data, true)['rows'];

// Get the devid and devcode parameters from the GET request
$devid = $_GET['devid'];
$devcode = $_GET['devcode'];

// Initialize an empty array to store the matching rows
$matchingRows = [];

// Loop through the rows and find the matching rows
foreach ($rows as $row) {
  if ($row['devid'] === $devid && $row['devcode'] === $devcode) {
    // Add the matching row to the array
    $matchingRows[] = $row;
  }
}

// Create an array with a single key 'rows', which maps to the matching rows
$output = ['rows' => $matchingRows];

// If at least one matching row was found, output them in JSON format
if (count($matchingRows) > 0) {
  header('Content-Type: application/json');
  echo json_encode($output);
} else {
  // If no matching row was found, output an error message
  //header('HTTP/1.1 404 Not Found');
  //echo 'Record not found';
  header('Content-Type: application/json');
  $final = json_encode('Record not found', JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  echo ($final);
}


?>