Registros duplicados con consulta INNER JOIN
Publicado por Paola (8 intervenciones) el 24/02/2020 00:04:01
Hola, mi problema es que al realizar la consulta, se duplican los registros de la tabla datos personales, sin embargo de la tabla formaciones no, y al añadir mas tablas abajo estas tambien se duplican. No se como solucionarlo, deberia usar un while o algo?
Aqui mi codigo:
Aqui mi codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$Connection = new PDO("mysql:host=localhost;dbname=proyecto1","root","");
$statement = $Connection->prepare("SELECT
usuarios.*, datospersonales.*, formacion.*
FROM usuarios
INNER JOIN datospersonales ON usuarios.documento = datospersonales.documento
INNER JOIN formacion ON usuarios.documento = formacion.documento
WHERE
usuarios.documento = :mi_parametro");
$statement->execute([
'mi_parametro' => $_SESSION['usuario']['documento']
]);
$registros = $statement->fetchAll(PDO::FETCH_OBJ);
if ($statement->rowCount() > 0) {
?>
<div class="content-wrapper">
<!-- Primera tabla-->
<div class="box-header"><h3 class="box-title"> Datos Personales </h3></div>
<div class="box-body table-responsive no-padding">
<table class=" table table-hover">
<tbody>
<?php
foreach ($registros as $registro) {
?>
<tr>
<th> Cedula de Identidad </th>
<td><?= $registro->documento ?></td>
</tr>
<tr>
<th>Fecha de Nacimiento</th>
<td><?= $registro->fnacimiento?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- Fin primera tabla-->
<!-- 2 tabla-->
<div class="box-header"><h3 class="box-title">Formación y Capacitacion</h3></div>
<div class="box-body table-responsive">
<table class="table">
<thead>
<tr>
<th>Titulo</th>
<th>Nivel de Estudio</th>
<th>Institución</th>
</tr>
</thead>
<tbody>
<?php
foreach ($registros as $formacion) {
?>
<tr>
<td><?= $formacion->titulo_carrera ?></td>
<td><?= $formacion->nivel_estudio ?></td>
<td><?= $formacion->universidad ?></td>
</tr>
<?php
}?>
</tbody>
</table>
</div>
</div>
<?php
} // Cerramos el if
?>
Valora esta pregunta


0