<?php
$conexao = new mysqli("localhost","root","","hospital");
if($conexao->connect_errno){
echo"Failed to connect to MySQL: (" . $conexao->connect_errno .") " . $conexao->connect_error;
}
$res = $conexao->query("SELECT nome, idade, cpf from paciente, ficha_atendimento, questionario WHERE paciente.id = ficha_atendimento.id_paciente AND paciente.id = questionario.id_paciente");
echo "<table class='table table-striped'>";
echo "<tr>
<td>Nome</td>
<td>Idade</td>
<td>CPF</td>
</tr>";
while($row = mysqli_fetch_assoc($res)) {
echo "<tr class='info'>
<td>". $row['nome']."</td>
<td>". $row['idade']."</td>
<td>". $row['cpf']."</td>
<td><a href='sala_questionario.php'><button class='btn btn-info'>Redirecionar</button></a></td>
</tr>";
}
echo "</table>";
?>
The 'patient' table has the fields name age and cpf, and all these are being printed on the table, next to a button (in the code above) that redirects the patient to a page that he will answer a questionnaire. However, I need to take the id of this patient to this next page when he is redirected so that when he answers the questionnaire the program sends the data to the 'questionnaire' table that has a foreign key called patient id that corresponds to the patient id of the patient (ie the problem is that everyone is being redirected to the same page, without differentiating who is responding to the questionnaire).