J'ai fait une demande CRUD pour recueillir des informations sur les patients.Php CRUD: montre les données de 2 tables liées dans une seule boucle while
Il y a 2 tables dans la base de données: utilisateurs et medical_records. La table "users" contient le médical personnel qui annonce les dossiers médicaux, en d'autres termes, les données au table medical_records.
L'ID utilisateur (uid
) est une clé étrangère dans la table des dossiers médicaux. Je veux afficher le nom complet de l'infirmier dans le tableau medical_records.
A cet effet, j'ai écrit cette requête, tout d'abord:
$sql = "SELECT `first_name`, `last_name` FROM users WHERE id =`" . $row['uid'] . "`";
et le résultat est souhaité un:
SELECT `first_name`, `last_name` FROM users WHERE id =`4;`
Mais faisant écho au nom complet comme si echo $row['first_name'] . $row['last_name'];
résulte en une erreur: Undefined index: first_name in path\to\medical_records_all_table.php
.
Tout le contexte où je suis en train d'extraire des données de deux tables à l'intérieur d'une seule boucle while est:
<table id="medical_records" class="table table-bordered table-striped" width="100%">
<thead>
<tr>
<th>Nume complet</th>
<th>Judet</th>
<th>Data internarii</th>
<th>Ora internarii</th>
<th>Data operatiei</th>
<th>Ora operatiei</th>
<th>Fisa adaugata de</th>
<th>Actiuni</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT `mid`, `uid`, `nume_complet`, `judet`, `data_internarii_mamei`, `ora_internarii_mamei`, `data_operatiei`, `ora_operatiei` FROM medical_records";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$mid = $row['mid'];
?>
<tr id="<?php echo $mid; ?>">
<td>
<a href="view_record.php?mid=<?php echo $mid; ?>">
<?php echo ucwords($row['nume_complet']); ?>
</a>
</td>
<td><?php echo $row['judet']; ?></td>
<td><?php echo $row['data_internarii_mamei']; ?></td>
<td><?php echo $row['ora_internarii_mamei']; ?></td>
<td><?php echo $row['data_operatiei']; ?></td>
<td><?php echo $row['ora_operatiei']; ?></td>
<td>
<?php
echo $sql = "SELECT `first_name`, `last_name` FROM users WHERE id =`" . $row['uid'] . ";`";
echo $row['first_name'] . $row['last_name'];
?>
</td>
<td class="actions">
<ul class="list-inline text-center">
<li>
<a title="Vezi fisa" href="view_record.php?mid=<?php echo $mid; ?>"><span class="glyphicon glyphicon-eye-open"></span></a>
</li>
<li>
<a title="Editeaza" href="edit_record.php?mid=<?php echo $mid; ?>"><span class="glyphicon glyphicon-edit"></span></a>
</li>
<li>
<a title="Sterge" class="delete-icn" href="#" data-mid="<?php echo $mid; ?>"><span class="glyphicon glyphicon-trash"></span></a>
</li>
</ul>
</td>
</tr>
<?php } mysqli_free_result($result); } ?>
</tbody>
</table>
Qu'est-ce que je manque?