PHP - consulta sql solo me muestra un registro de la bd

 
Vista:
sin imagen de perfil

consulta sql solo me muestra un registro de la bd

Publicado por manuel (1 intervención) el 27/04/2018 19:58:17
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
<?php
 
	session_start();
	include '2.php';
 
	if(!isset($_SESSION["usuario"])){
		header("Location:1.php");
	}
?>
<?php
	$Usuario = $_SESSION['usuario'];
 
	$sql = "SELECT*FROM usuarios WHERE usuario = '$Usuario'";
	$result=$mysqli->query($sql);
 
	$datos = $result->fetch_assoc();
 
?>
 
<!DOCTYPE html>
<html>
<head>
</head>
	<body>
		<table>
            <tr>
				<td style="text-align:center">ID</td>
				<td style="text-align:center">USUARIO</td>
				<td style="text-align:center">PASSWORD</td>
				<td style="text-align:center">IDP</td>
				<td style="text-align:center">IDT</td>
            </tr>
 
        <tr>
            <td style="text-align:center"><?php echo utf8_decode( $datos['id']); ?></td>
            <td style="text-align:center"><?php echo utf8_decode( $datos['usuario']); ?></td>
            <td style="text-align:center"><?php echo utf8_decode($datos['password']); ?></td>
            <td style="text-align:center"><?php echo utf8_decode($datos['id_personal']); ?></td>
            <td style="text-align:center"><?php echo utf8_decode( $datos['id_tipo']); ?></td>
        </tr>
 
	</table>
</form>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

consulta sql solo me muestra un registro de la bd

Publicado por Yamil Bracho (888 intervenciones) el 27/04/2018 20:07:46
1) Chequea si realmente tu consulta te retorna multiple registros
2) Si es asi, entonces debes usar un foreach o un ciclo para iterar atraves del conjunto de datos que te retorna la consulta

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
<?php
 
session_start();
include '2.php';
 
if(!isset($_SESSION["usuario"])){
	header("Location:1.php");
}
?>
<?php
	$Usuario = $_SESSION['usuario'];
 
	$sql = "SELECT*FROM usuarios WHERE usuario = '$Usuario'";
	$result=$mysqli->query($sql);
?>
 
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<tr>
<td style="text-align:center">ID</td>
<td style="text-align:center">USUARIO</td>
<td style="text-align:center">PASSWORD</td>
<td style="text-align:center">IDP</td>
<td style="text-align:center">IDT</td>
</tr>
 
<? php
	while ($datos = $result->fetch_assoc()) {
?>
<tr>
<td style="text-align:center"><?php echo utf8_decode( $datos['id']); ?></td>
<td style="text-align:center"><?php echo utf8_decode( $datos['usuario']); ?></td>
<td style="text-align:center"><?php echo utf8_decode($datos['password']); ?></td>
<td style="text-align:center"><?php echo utf8_decode($datos['id_personal']); ?></td>
<td style="text-align:center"><?php echo utf8_decode( $datos['id_tipo']); ?></td>
</tr>
<? php
}
?>
</table>
</form>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar