Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/06/2013, 10:39
spark21
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
tabla con varios criterios en php con sql.

Hola, estoy intentando crear una tabla, soy novato y no tengo mucha idea de php ni sql.

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:



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:
Código PHP:
<?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.



Además quiero hacer otra pregunta, en lugar de mostrar un 1 en la tabla ¿cómo podría hacer para que muestre una imagen? muchas gracias de antemano por la ayuda.