<?php 

$sqldata = "SELECT * FROM questions WHERE id_grille = '" . $_SESSION['id_grille'] . "' AND id_patient = '" . $_SESSION['id_patient'] . "' AND date = DATE(NOW())";
$reqdata = cleanPDOQuery($sqldata);
$total = $reqdata->rowCount();

	if ($total != 0) {
		$k = 0;
		while($resdata = $reqdata->fetch())
		{
			$reponse[$k] = $resdata['reponse'];
			$id_question[$k] = $resdata['id_question'];
			$k++;
		}

?>

<form name="formQ" style="color: black; margin-left: 40%;">
	<table>
		<tr><th style="width:30%;">Questions</th><th>Nombre</th></tr>
		<?php
			for($i = 0; $i < $total; $i++)
			{	
				echo '<tr><td>Question ' . $id_question[$i] . '</td>';
				echo '<td><input style="margin:5px;text-align:center;" type="tel" name="number2_' . $id_question[$i] . '" value="'. $reponse[$i] .'""';
				echo '/></td></tr>';
			}
			
		?>
	</table>
</form>
<a href="#" style="color:black;" onclick="updateQuestions(1, 'Num');updateQuestions(2, 'Num');updateQuestions(3, 'Num');">Envoyer</a>
<?php
	}
	else {
	?>
		<form name="formQ" style="text-align:center; color: black; margin-left: 40%;">
			<table>
				<tr><th style="width:30%;">Questions</th><th>Nombre</th></tr>
				<tr><td>Question 1</td><td><input style="margin:5px;text-align:center;" value="0" type="tel" name="number2_1" /></td></tr>
				<tr><td>Question 2</td><td><input style="margin:5px;text-align:center;" value="0" type="tel" name="number2_2" /></td></tr>
				<tr><td>Question 3</td><td><input style="margin:5px;text-align:center;" value="0" type="tel" name="number2_3" /></td></tr>
			</table>
		</form>
		<a href="#" style="color:black;" onclick="updateQuestions(1, 'Num');updateQuestions(2, 'Num');updateQuestions(3, 'Num');">Envoyer</a>
	<?php
	}
	?>