<?php

header("Content-type: application/json; charset=utf-8");
$servername = "localhost";
$username = "eepaznzs";
$password = "ryY3pT9a84";
$dbname_process = "eepaznzs_process";

set_time_limit(0);

$conn = new mysqli($servername, $username, $password, $dbname_process);
mysqli_set_charset($conn, "utf8");
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$codes = $_GET["codes"];
$codes = explode("," , $codes);

$answers = array();

for ($i=0; $i<sizeof($codes); $i++){
    $code = $codes[$i];
   // $result_process = $conn->query("SELECT * FROM process WHERE `code`='$code' LIMIT 1");
   // if ($result_process->num_rows > 0) {
       // while ($row_process = $result_process->fetch_assoc()) {
        
            $token = $code;
            $result_user = $conn->query("SELECT * FROM users WHERE `token`='$token'");
            if ($result_user->num_rows > 0) {
                while ($row_users = $result_user->fetch_assoc()) {
                    $res["code"] = $token;
                    $res["weight"] = $row_users["weight"];
                    $res["weight_goal"] = $row_users["weight_goal"];
                    $res["height"] = $row_users["height"];
                    $res["matcha_length"] = $row_users["programLength"];

                    array_push($answers , $res);
                }
            }
       // }
   // }
}


$response['answers'] = $answers;
$json_response = json_encode($response);
echo $json_response;
die();