<?php
	session_start(); 
	
	include("connexion_db.php");
	
	if(isset($_SESSION['etat']) && $_SESSION['etat'] == 'search')
	{	
		if(isset($_GET['value']) && $_GET['value'] != '')
		{	
			$value = $_GET['value'];
			$sql = "SELECT * FROM patient";
			$req = cleanPDOQuery($sql);	
			$i = 0;
			while ($res = $req->fetch()) {
				$i++;
				if ($i == $value) {
					$resultat['id'] = $res['id'];
					$resultat['chambre'] = $res['chambre'];
					$resultat['nom'] = $res['nom'];
					$resultat['prenom'] = $res['prenom'];
					$resultat['age'] = $res['date_naissance'];
					$resultat['sexe'] = $res['sexe'];
					$resultat['texte'] = $res['texte'];
				}
			}
			
			header('Content-Type: application/json');
			echo json_encode($resultat);
		}
	}

	
?>