SQL - Los datos no salen correctamente en la tabla.

 
Vista:

Los datos no salen correctamente en la tabla.

Publicado por spark21 (1 intervención) el 30/06/2013 20:52:17
Hola, estoy intentando crear una tabla, soy novato y no tengo mucha idea de php ni sql. Aunque ya he leído sobre sentences etc, y en teoría he puesto lo que he leído buscando en google, también con la ayuda de DW, pero no sale del todo como quiero.

Se trata de recoger en una tabla un registro de sucesos, la consulta en base de datos (phpmyadmin) me devuelve bien los datos que quiero, pero en la tabla php se inventa datos.

Seré más especifico, una persona manda unos datos y estos datos se guardan en una tabla de esta forma, los datos que se envían se graban en horizontal, hay otra columna llamada accepted que toma valor 0, 1 o 2:



Entonces, yo quiero crear una tabla en php, que indique un listado de quienes mandaron esos datos según dos criterios, si el numero de identificación de ese envió "flightnum" corresponde con el criterio que yo quiero (HAWx) y si está con el valor accepted= 1. (aceptado)

Resulta que he hecho la tabla, pero intencionadamente borre de la tabla el flightnum HAW3 del usuario (pilotid) 187 y sin embargo sigue apareciendo con el valor 1 de aceptado.

Dejo aquí el código de la tabla:

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php virtual('/phpvms/Connections/byethost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_byethost, $byethost);
$query_piloto = "SELECT `phpvms_pireps`.`pilotid` FROM phpvms_pireps WHERE ( ( `phpvms_pireps`.`flightnum` = 'HAW1' ) AND ( `phpvms_pireps`.`accepted` =1 ) ) ORDER BY `phpvms_pireps`.`pilotid` ASC LIMIT 0 , 30";
$piloto = mysql_query($query_piloto, $byethost) or die(mysql_error());
$row_piloto = mysql_fetch_assoc($piloto);
$totalRows_piloto = mysql_num_rows($piloto);
 
mysql_select_db($database_byethost, $byethost);
$query_ruta1 = "SELECT `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ( ( `phpvms_pireps`.`flightnum` = 'HAW1' ) AND ( `phpvms_pireps`.`accepted` =1 ) ) ORDER BY `phpvms_pireps`.`pilotid` ASC LIMIT 0 , 30";
$ruta1 = mysql_query($query_ruta1, $byethost) or die(mysql_error());
$row_ruta1 = mysql_fetch_assoc($ruta1);
$totalRows_ruta1 = mysql_num_rows($ruta1);
 
mysql_select_db($database_byethost, $byethost);
$query_ruta2 = "SELECT `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`flightnum` ='HAW2') AND (`phpvms_pireps`.`accepted` =1)) ORDER BY `phpvms_pireps`.`pilotid` ASC";
$ruta2 = mysql_query($query_ruta2, $byethost) or die(mysql_error());
$row_ruta2 = mysql_fetch_assoc($ruta2);
$totalRows_ruta2 = mysql_num_rows($ruta2);
 
mysql_select_db($database_byethost, $byethost);
$query_ruta4 = "SELECT `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`flightnum` ='HAW4') AND (`phpvms_pireps`.`accepted` =1)) ORDER BY `phpvms_pireps`.`pilotid` ASC";
$ruta4 = mysql_query($query_ruta4, $byethost) or die(mysql_error());
$row_ruta4 = mysql_fetch_assoc($ruta4);
$totalRows_ruta4 = mysql_num_rows($ruta4);
 
mysql_select_db($database_byethost, $byethost);
$query_ruta3 = "SELECT `phpvms_pireps`.`accepted`
FROM phpvms_pireps
WHERE ((`phpvms_pireps`.`flightnum` ='HAW3') AND (`phpvms_pireps`.`accepted` =1))
ORDER BY `phpvms_pireps`.`pilotid` ASC";
$ruta3 = mysql_query($query_ruta3, $byethost) or die(mysql_error());
$row_ruta3 = mysql_fetch_assoc($ruta3);
$totalRows_ruta3 = mysql_num_rows($ruta3);
?>
<!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>Tabla de tours</title>
</head>
 
<body>
<table border="5">
  <tr>
    <td>pilotid</td>
    <td>Ruta 1</td>
    <td>Ruta 2</td>
    <td>Ruta 3</td>
    <td>Ruta 4</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_piloto['pilotid']; ?></td>
      <td><?php echo $row_ruta1['accepted']; ?></td>
      <td><?php echo $row_ruta2['accepted']; ?></td>
      <td><?php echo $row_ruta3['accepted']; ?></td>
      <td><?php echo $row_ruta4['accepted']; ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <?php } while ($row_piloto = mysql_fetch_assoc($piloto)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($piloto);
 
mysql_free_result($ruta1);
 
mysql_free_result($ruta2);
 
mysql_free_result($ruta3);
 
mysql_free_result($ruta4);
 
 
?>


Aquí como se sitúan en la tabla:


Y aquí como muestra el resultado, no debería salir la ruta 3 (HAW3) para el pilotid (usuario) 187, y sin embargo sale.
En phpmyadmin ejecutando la consulta sql sale el resultado correcto.



Gracias de antemano, y un saludo.
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