PHP - Mostrar total

 
Vista:
sin imagen de perfil

Mostrar total

Publicado por Óscar (3 intervenciones) el 30/01/2016 11:11:38
Buenos días compañeros, soy nuevo en programación en PHP y estoy intentando hacer una especie de web de pedidos de taxis.
Tengo un pequeño problema a la hora de mostrar un dato.
Os dejo parte del código para ver si me podéis orientar un poquillo.
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>LISTADO GENERAL DE TAXIS</title>
<link rel="stylesheet" href="tabla.css" />
</head>
 
<body>
<?php
$conexion = @mysqli_connect(.........;
 
$sel = "SELECT * FROM taxis";
//Ejecutamos la secuencia SQL
$exec = mysqli_query($conexion, $sel);
$libres=0;
?>
 
<table border="1">
<tr><td>Matrícula</td>
<td>Modelo</td>
<td>Conductor</td>
<td>Ocupado</td>
</tr>
 
<?php
//Mediante while recorremos la tabla
while ($registro=mysqli_fetch_array($exec)) { //Devuelve el array y rellena los campos
?>
<tr>
<td><?php echo($registro["Matricula"]); ?></td>
<td><?php echo($registro["Modelo"]); ?></td>
<td><?php echo($registro["Nombre"] . " " . $registro["Apellidos"]); ?></td>
<td><?php
if ($registro=="Ocupado")
echo("Si");
else {
$libres++;
echo("No");
}
?></td>
</tr>
<?php
}
 
//Cerramos la conexión después del bucle
mysqli_close($conexion);
?>
<TR>
<TD COLSPAN="6" align="center"><font color="red"><b>
Taxis Libres: <?php echo($libres);?> - Total Taxis: <?php echo(mysqli_affected_rows()); ?>
</B></font></TD></TR>
</table>
 
</body>
</html>

En las últimas líneas si que me muestra los taxis libres, pero el total de taxis me da un Warning: mysqli_affected_rows() expects exactly 1 parameter, 0 given in C:\xampp\

¿Como puedo hacer para mostrar el total de taxis y no solo los disponibles?
Gracias de antemano.
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

Mostrar total

Publicado por Óscar (3 intervenciones) el 30/01/2016 12:03:05
Ya está solucionado, Gracias!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Mostrar total

Publicado por xve (6935 intervenciones) el 30/01/2016 19:57:10
Donde estaba el problema Óscar?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Mostrar total

Publicado por Óscar (3 intervenciones) el 31/01/2016 10:57:40
Hola xve, corregí un if que estaba mal e inicié el mysqli_affected_rows en una variable al principio.

Enseño la corrección.

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
<body>
<?php
$conexion = @mysqli_connect("l.........................");
 
$sel = "SELECT * FROM taxis";
//Ejecutamos la secuencia SQL
$exec = mysqli_query($conexion, $sel);
$result = mysqli_affected_rows($conexion);
$libres=0;
?>
<table border="1">
<tr><td>Matrícula</td>
<td>Modelo</td>
<td>Conductor</td>
<td>Ocupado</td>
</tr>
 
<?php
//Mediante while recorremos la tabla
while ($registro=mysqli_fetch_array($exec)) { //Devuelve el array y rellena los campos
?>
<tr>
<td><?php echo($registro["Matricula"]); ?></td>
<td><?php echo($registro["Modelo"]); ?></td>
<td><?php echo($registro["Nombre"] . " " . $registro["Apellidos"]); ?></td>
<td><?php
if ($registro["Ocupado"])
echo("Si");
else {
$libres++;
echo("No");
}
?></td>
</tr>
<?php
}
 
//Cerramos la conexión después del bucle
 
?>
 
<TR>
<TD COLSPAN="6" align="center"><font color="red"><b>
Taxis Libres: <?php echo($libres);?> - Total Taxis: <?php echo($result); ?>
</font></TD></TR>
</table>
 
</body>
</html>

Saludos!!
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