<?php
header('Access-Control-Allow-Origin: *');
header("Content-type: application/json; charset=utf-8");

//error_reporting(0);

include '../../utils/database.php';
include '../../utils/helper.php';

$dbname_process_test = "mintdoct_process_test";

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

$qids= array();
$resultAnswers = $conn->query("SELECT * FROM questionsV2 WHERE `type`='fit' order by id");
if ($resultAnswers->num_rows > 0) {
   while ($row_an = $resultAnswers->fetch_assoc()) {
        $qid = $row_an["qid"];
        if (!in_array($qid , $qids)){
            array_push($qids , $qid);
        }
   }
}

$last3Hour = time() - (4*3600);



for ($i=0; $i<sizeof($qids); $i++){

    $resultAnswers = $conn->query("SELECT * FROM process WHERE `qid`='$qids[$i]' AND `created_at` > $last3Hour");
    
    echo "qid: " . $qids[$i] . "  " . $resultAnswers->num_rows . "\n\n";

}