Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] else if echo imagen en tabla

Estas en el tema de else if echo imagen en tabla en el foro de PHP en Foros del Web. Hola, estamos intentando crear una tabla que devuelva unos resultados de la base de datos, hasta ahí bien, el problema es que queremos que nos ...
  #1 (permalink)  
Antiguo 30/01/2015, 06:11
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
else if echo imagen en tabla

Hola, estamos intentando crear una tabla que devuelva unos resultados de la base de datos, hasta ahí bien, el problema es que queremos que nos muestre una imagen alojada en el servidor, si el valor de la consulta es 1 muestre vistobueno.jpg, si es 2 muestre vistomalo.png, y si no es ninguno de los dos aparezca en blanco, nada.

Os dejo el código y la url:

http://www.argavirtual.com/lib/skins/TABLA%20DE%20JOSE.php

Código:
mysql_select_db($database_byethost, $byethost);
$query_tabladetours = "SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-1') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours = mysql_query($query_tabladetours, $byethost) or die(mysql_error());
$row_tabladetours = mysql_fetch_assoc($tabladetours);
$totalRows_tabladetours = mysql_num_rows($tabladetours);


mysql_select_db($database_byethost, $byethost);
$query_tabladetours1 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-2') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours1= mysql_query($query_tabladetours1, $byethost) or die(mysql_error());
$row_tabladetours1= mysql_fetch_assoc($tabladetours1);
$totalRows_tabladetours1= mysql_num_rows($tabladetours1);

mysql_select_db($database_byethost, $byethost);
$query_tabladetours2 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-3') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours2= mysql_query($query_tabladetours2, $byethost) or die(mysql_error());
$row_tabladetours2= mysql_fetch_assoc($tabladetours2);
$totalRows_tabladetours2= mysql_num_rows($tabladetours2);

mysql_select_db($database_byethost, $byethost);
$query_tabladetours3 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-4') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours3= mysql_query($query_tabladetours3, $byethost) or die(mysql_error());
$row_tabladetours3= mysql_fetch_assoc($tabladetours3);
$totalRows_tabladetours3= mysql_num_rows($tabladetours3);
Código:
<table border="5" align="left">
  <tr>
    <td bgcolor="#CC3300"><div align="center"><strong>ID de piloto ARV:</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-1</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-2</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-3</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-4</strong></div></td>  
    </div></td>
  </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#FFFFFF"><strong>ARV</strong><?php echo $row_tabladetours['pilotid']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours1['accepted']; ?><?php if ($row_tabladetours1->accepted == 1) {echo "<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif''></img>";}
  elseif ($row_tabladetours1->accepted == 2) {echo "<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'></img>";}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours2['accepted']; ?><?php if ($row_tabladetours2->accepted == 1) {echo '<img src="http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif"></img>';}
  elseif ($row_tabladetours2->accepted == 2){ echo '<img src="http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png"></img>';}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours3['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td> 
    </tr>
    <?php } while ($row_tabladetours = mysql_fetch_assoc($tabladetours));
            while ($row_tabladetours1 = mysql_fetch_assoc($tabladetours1));?>
</table>


<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($tabladetours);
mysql_free_result($tabladetours1);
?>
  #2 (permalink)  
Antiguo 30/01/2015, 08:40
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

A ver...cuesta un poco enterarse si no pones el codigo en la etiqueta PHP.
¿Tal y como esta el codigo que muestra? ¿Que error da?
Usais if, elseif pero os falta el else.

Lo que pretendeis se haria algo asi:

Código PHP:
if($row['$1']==1){
echo (
"Mostrar imagen 1");
}

elseif(
$row['$1']==2){
echo (
"Mostrar imagen 2");
}

else{
echo(
"No mostrar nada");

Pero ya digo, no se cual es el error que teneis ni he podido leer muy bien el codigo.
  #3 (permalink)  
Antiguo 30/01/2015, 09:21
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Hola, gracias por contestar,

No nos da ningún error, simplemente hemos aplicado el código que supuestamente llama echo a una imagen cuando "elseif" de la columna "accepted" es 1 u otra imagen si es 2. cada dibujo va en una celda de la tabla.
Es como un check point, tiene la ruta "A" hecha, sí (1) entonces muestra el dibujo vistobueno.jpg, no (2) entonces muestra el dibujo vistomalo.jpg.
Cada ruta está nombrada como tabladetours, tabladetours2, etc.

Pero tal y como se ve en el enlace no termina de mostrar el dibujo en la ruta ANT-2:
http://www.argavirtual.com/lib/skins/TABLA%20DE%20JOSE.php

ANT-3 no se ve porque el valor es 0 y quiero que no muestre nada, si fuese 2 querría el vistomalo.png

Vuelvo a poner el código pero con la etiqueta php

Código PHP:
mysql_select_db($database_byethost$byethost);
$query_tabladetours "SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-1') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours mysql_query($query_tabladetours$byethost) or die(mysql_error());
$row_tabladetours mysql_fetch_assoc($tabladetours);
$totalRows_tabladetours mysql_num_rows($tabladetours);


mysql_select_db($database_byethost$byethost);
$query_tabladetours1 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-2') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours1mysql_query($query_tabladetours1$byethost) or die(mysql_error());
$row_tabladetours1mysql_fetch_assoc($tabladetours1);
$totalRows_tabladetours1mysql_num_rows($tabladetours1);

mysql_select_db($database_byethost$byethost);
$query_tabladetours2 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-3') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours2mysql_query($query_tabladetours2$byethost) or die(mysql_error());
$row_tabladetours2mysql_fetch_assoc($tabladetours2);
$totalRows_tabladetours2mysql_num_rows($tabladetours2);

mysql_select_db($database_byethost$byethost);
$query_tabladetours3 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-4') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours3mysql_query($query_tabladetours3$byethost) or die(mysql_error());
$row_tabladetours3mysql_fetch_assoc($tabladetours3);
$totalRows_tabladetours3mysql_num_rows($tabladetours3); 
Código PHP:
<table border="5" align="left">
  <tr>
    <td bgcolor="#CC3300"><div align="center"><strong>ID de piloto ARV:</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-1</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-2</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-3</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-4</strong></div></td>  
    </div></td>
  </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#FFFFFF"><strong>ARV</strong><?php echo $row_tabladetours['pilotid']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours1['accepted']; ?><?php if ($row_tabladetours1->accepted == 1) {echo "<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></img>";}
  elseif (
$row_tabladetours1->accepted == 2) {echo "<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'></img>";}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours2['accepted']; ?><?php if ($row_tabladetours2->accepted == 1) {echo '<img src="http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif"></img>';}
  elseif (
$row_tabladetours2->accepted == 2){ echo '<img src="http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png"></img>';}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours3['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td> 
    </tr>
    <?php } while ($row_tabladetours mysql_fetch_assoc($tabladetours));
            while (
$row_tabladetours1 mysql_fetch_assoc($tabladetours1));?>
</table>


<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($tabladetours);
mysql_free_result($tabladetours1);
?>
  #4 (permalink)  
Antiguo 30/01/2015, 09:26
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

Revisa las comillas

echo" <img src='http...'> "
En algunos los has puesto el contrario o has cerrado con las comillas que no son.
  #5 (permalink)  
Antiguo 30/01/2015, 09:28
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Sí, es porque en dos ejemplos lo vi de distinta forma, los voy a poner como me lo indicas.
  #6 (permalink)  
Antiguo 30/01/2015, 09:53
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

No sé si lo he puesto bien, me he centrado en la "ANT-2" para no tener tanto código cambiado.
Algo debo de estar haciendo mal porque solo muestra "No mostrar nada"

Código PHP:
<?php do { ?>
    <tr>
      <td bgcolor="#FFFFFF"><strong>ARV</strong><?php echo $row_tabladetours['pilotid']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours1['accepted']; ?><?php if ($row_tabladetours1->accepted == "1") {echo "src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>";} elseif ($row_tabladetours1->accepted == "2") {echo "src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>";} else{
echo(
"No mostrar nada");

?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours2['accepted']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours3['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td> 
    </tr>
  #7 (permalink)  
Antiguo 30/01/2015, 11:34
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

Prueba asi:

Código PHP:
<?php do { ?>
    <tr>
      <td bgcolor="#FFFFFF"><strong>ARV</strong><?php echo $row_tabladetours['pilotid']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours1['accepted']; ?><?php if ($row_tabladetours1->accepted == '1') {echo ("<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");} elseif ($row_tabladetours1->accepted == '2') {echo ("<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");} else{
echo(
"No mostrar nada");

?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours2['accepted']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours3['accepted']; ?><img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'></td> 
    </tr>
Y dime si funciona o que te sale para ir descartando.
  #8 (permalink)  
Antiguo 30/01/2015, 13:38
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Hola, he sustituido el que tenia por el tuyo, y error de nuevo ninguno, simplemente aparece el valor 1 (que representa aceptado ok) y al lado el texto "No mostrar nada". Es como si no entendiera que tiene que poner la imagen al haber 1.

http://www.argavirtual.com/lib/skins/TABLA%20DE%20JOSE.php
  #9 (permalink)  
Antiguo 30/01/2015, 13:56
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

A ver, hay una cosa que no entiendo.
¿Por que hace echo $row_tabladetours['accepted']; 4 veces?
Es decir, si haces ese echo te va a salir las 4 veces el valor que tenga esa variable.

Por otro lado, vamos a olvidarnos de las tablas y lo demas porque como no acabo de entender todo el codigo, hagamoslo a lo simple y bestia.

Haces el SELECT y todo eso hasta llegar a
Código PHP:
$row_tabladetours mysql_fetch_assoc($tabladetours); 
Y a partir de ahi prueba lo siguiente para que veamos si funciona o si el error esta en otro sitio:

Código PHP:
if($row_tabladetours['accepted']=='1'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif(
$row_tabladetours['accepted']=='2'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo(
"No mostar nada"); 
Es decir, pon solo eso, nada de tablas ni otros trozos de codigo.
Excepto que haya un error en la llamada a la BDD en la que haces el SELECT, deberia funcionar.
  #10 (permalink)  
Antiguo 30/01/2015, 14:13
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Lo de las 4 veces es porque le preguntamos si el piloto 0377 ha hecho el vuelo ANT-1, y nos muestre su resultado (1, 2, 0 //aceptado, rechazado, pendiente de aceptar), después preguntamos si ha hecho el vuelo ANT-2 etc. hasta llegar a ANT-4.

Sale el código con las imágenes

Código 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_tabladetours "SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-1') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours mysql_query($query_tabladetours$byethost) or die(mysql_error());
$row_tabladetours mysql_fetch_assoc($tabladetours);
$totalRows_tabladetours mysql_num_rows($tabladetours);


mysql_select_db($database_byethost$byethost);
$query_tabladetours1 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-2') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours1mysql_query($query_tabladetours1$byethost) or die(mysql_error());
$row_tabladetours1mysql_fetch_assoc($tabladetours1);
$totalRows_tabladetours1mysql_num_rows($tabladetours1);

mysql_select_db($database_byethost$byethost);
$query_tabladetours2 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-3') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours2mysql_query($query_tabladetours2$byethost) or die(mysql_error());
$row_tabladetours2mysql_fetch_assoc($tabladetours2);
$totalRows_tabladetours2mysql_num_rows($tabladetours2);

mysql_select_db($database_byethost$byethost);
$query_tabladetours3 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-4') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours3mysql_query($query_tabladetours3$byethost) or die(mysql_error());
$row_tabladetours3mysql_fetch_assoc($tabladetours3);
$totalRows_tabladetours3mysql_num_rows($tabladetours3);

?>
if($row_tabladetours['accepted']=='1'){
echo ("<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif($row_tabladetours['accepted']=='2'){
echo ("<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo("No mostar nada");


<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($tabladetours);
mysql_free_result($tabladetours1);
?>
  #11 (permalink)  
Antiguo 30/01/2015, 14:21
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

¿Como que sale el codigo con las imagenes?
No entiendo bien que quieres decir con eso
Jajajajaja

A ver, repasando la consulta no la entiendo bien.
No entiendo la necesidad de usar las comillas (las que son acentos).

La consulta a la tabla debe ser:

Código PHP:
$sql "SELECT dato1, dato2, dato3 FROM tabla WHERE dato4 = 'variable' AND dato5 = 'variable2'";

$result=mysqli_query($sql$conectar);
//o como conectes tu, eso da igual

$row=mysql_fetch_assoc($result);

//y ahi ya sigues con el if 
Vamos, que elimines las comillas y parentesis innecesarios.

Y otra cosa, lo de ORDER BY me hace pensar una cosa, la consulta no arrojaria solo un resultado?

Porque si arroja mas de uno, mysql_fetch_assoc no nos sirve, habria que realizar un array.
  #12 (permalink)  
Antiguo 30/01/2015, 14:29
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Si miras la url veras a lo que me refiero:
http://www.argavirtual.com/lib/skins/TABLA%20DE%20JOSE.php

El código nos sale así de phpmyadmin cuando hacemos consultas,

De momento solo hay un resultado, piloto número de vuelo aceptado/rechazado/pendiente.
Pero la intención es que muestre todos los pilotos que cumplan haber realizado alguno de esos vuelos.
  #13 (permalink)  
Antiguo 30/01/2015, 14:32
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

La verdad es que andamos muy pez en estos temas, no sé ni como hemos conseguido llegar hasta aquí. Muchas gracias por la ayuda que estás dando.
  #14 (permalink)  
Antiguo 30/01/2015, 14:32
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

Vale, vale.
Es que la ultima parte del codigo no esta dentro de <?php ?>

Metelo y prueba de nuevo!
  #15 (permalink)  
Antiguo 30/01/2015, 14:36
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Código PHP:
<?php
if($row_tabladetours['accepted']=='1'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif(
$row_tabladetours['accepted']=='2'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo(
"No mostar nada");
?>

<?php
mysql_free_result
($tabladetours);
mysql_free_result($tabladetours1);
mysql_free_result($tabladetours2);
mysql_free_result($tabladetours3);
?>
Parse error: syntax error, unexpected $end in /home/argavirt/public_html/lib/skins/TABLA DE JOSE.php on line 76
Línea 76 es la última de este código
  #16 (permalink)  
Antiguo 30/01/2015, 14:38
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

Falta el } que cierra el else!

Es decir,
else{
echo("No mostar nada");
}
  #17 (permalink)  
Antiguo 30/01/2015, 14:40
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Listo! ahora solo muestra la imagen.
  #18 (permalink)  
Antiguo 30/01/2015, 14:40
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

Perfecto, ahora extrapolalo a tu codigo y comprueba que siga funcionando!!
  #19 (permalink)  
Antiguo 30/01/2015, 15:36
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Vale, gracias.

Ya por curiosidad, por si podemos ahorrarnos hacer todo esto con cada piloto especificando el número de piloto.

Hemos modificado esto para que muestre el vistomalo también, quitando el =1 y funciona correctamente, y también el número de piloto para que nos devuelva el listado de todos los pilotos que han hecho algún vuelo llamado ANT-1, ANT-2 etc.
Pero esto último a pesar de listar todos los pilotos correctamente les marca a todos como vistobueno cuando no es así en todos:

"SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-1') AND (`phpvms_pireps`.`accepted` ='1')) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";

"SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid`) AND (`phpvms_pireps`.`flightnum` = 'ANT-1') AND (`phpvms_pireps`.`accepted`)) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";

Si es complicado lo hacemos a mano por cada piloto, que ya has ayudado mucho.

Muchísimas gracias!
  #20 (permalink)  
Antiguo 30/01/2015, 21:58
 
Fecha de Ingreso: mayo-2013
Mensajes: 171
Antigüedad: 10 años, 11 meses
Puntos: 4
Respuesta: else if echo imagen en tabla

No lo he entendido mucho...
Jajajaja

A parte de la consulta (SELECT) despues has vuelto a hacer el if?
Porque me dices que marca a todos con vistobueno.

A ver si puedes copiar todo el codigo y lo miramos.
  #21 (permalink)  
Antiguo 31/01/2015, 04:25
 
Fecha de Ingreso: diciembre-2007
Mensajes: 38
Antigüedad: 16 años, 3 meses
Puntos: 1
Respuesta: else if echo imagen en tabla

Cuando ponemos que nos muestre un piloto concreto en este caso 0377 sale correcto, el vuelo ANT-1 aceptado (valor 1)y el ANT-2 rechazado (valor 2). Estas peticiones hacemos una por cada vuelo, ANT-1, ANT-2, etc. Si participan diez pilotos tendríamos que hacer esto diez veces sabiendo de antemano cuales participan para añadirlos al código.

Entonces si borramos = '0377' nos muestra todos los pilotos automáticamente que han hecho alguno de esos vuelos pero lo hace incorrectamente, ya que por ejemplo el 0377 tiene marcado el ANT-2 como rechazado (valor 2) y a todos les pone aceptado (valor 1) sea verdad o no.
Código 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_tabladetours "SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-1') AND (`phpvms_pireps`.`accepted`)) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours mysql_query($query_tabladetours$byethost) or die(mysql_error());
$row_tabladetours mysql_fetch_assoc($tabladetours);
$totalRows_tabladetours mysql_num_rows($tabladetours);


mysql_select_db($database_byethost$byethost);
$query_tabladetours1 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-2') AND (`phpvms_pireps`.`accepted`)) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours1mysql_query($query_tabladetours1$byethost) or die(mysql_error());
$row_tabladetours1mysql_fetch_assoc($tabladetours1);
$totalRows_tabladetours1mysql_num_rows($tabladetours1);

mysql_select_db($database_byethost$byethost);
$query_tabladetours2 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-3') AND (`phpvms_pireps`.`accepted`)) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours2mysql_query($query_tabladetours2$byethost) or die(mysql_error());
$row_tabladetours2mysql_fetch_assoc($tabladetours2);
$totalRows_tabladetours2mysql_num_rows($tabladetours2);

mysql_select_db($database_byethost$byethost);
$query_tabladetours3 ="SELECT `phpvms_pireps`.`pilotid`, `phpvms_pireps`.`accepted` FROM phpvms_pireps WHERE ((`phpvms_pireps`.`pilotid` = '0377') AND (`phpvms_pireps`.`flightnum` = 'ANT-4') AND (`phpvms_pireps`.`accepted`)) ORDER BY `phpvms_pireps`.`pilotid` ASC , `phpvms_pireps`.`flightnum` ASC , `phpvms_pireps`.`accepted` ASC LIMIT 0 , 30";
$tabladetours3mysql_query($query_tabladetours3$byethost) or die(mysql_error());
$row_tabladetours3mysql_fetch_assoc($tabladetours3);
$totalRows_tabladetours3mysql_num_rows($tabladetours3);

?>
<table border="5" align="left">
  <tr>
    <td bgcolor="#CC3300"><div align="center"><strong>ID de piloto ARV:</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-1</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-2</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-3</strong></div></td>
    <td bgcolor="#CC3300"><div align="center"><strong>ANT-4</strong></div></td>  
    </div></td>
  </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#FFFFFF"><strong>ARV</strong><?php echo $row_tabladetours['pilotid']; ?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours['accepted']; ?><?php
if($row_tabladetours['accepted']=='1'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif(
$row_tabladetours['accepted']=='2'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo(
"No mostar nada");}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours1['accepted']; ?><?php
if($row_tabladetours1['accepted']=='1'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif(
$row_tabladetours1['accepted']=='2'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo(
"No mostar nada");}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours2['accepted']; ?><?php
if($row_tabladetours2['accepted']=='1'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif(
$row_tabladetours2['accepted']=='2'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo(
"No mostar nada");}
?></td>
      <td bgcolor="#FFFFFF"><?php echo $row_tabladetours3['accepted']; ?><?php
if($row_tabladetours3['accepted']=='1'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistobueno.gif'>");
}
elseif(
$row_tabladetours3['accepted']=='2'){
echo (
"<img src='http://argavirtual.com/lib/skins/templatemo_254_agency/images/vistomalo.png'>");
}
else{
echo(
"No mostar nada");}
?></td> 
    </tr>
    <?php } while ($row_tabladetours mysql_fetch_assoc($tabladetours));
            while (
$row_tabladetours1 mysql_fetch_assoc($tabladetours1));
            while (
$row_tabladetours2 mysql_fetch_assoc($tabladetours2));
            while (
$row_tabladetours3 mysql_fetch_assoc($tabladetours3));?>
</table>


<?php
mysql_free_result
($tabladetours);
mysql_free_result($tabladetours1);
mysql_free_result($tabladetours2);
mysql_free_result($tabladetours3);
?>

Etiquetas: echo, mysql, select, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:08.