Ver Mensaje Individual
  #6 (permalink)  
Antiguo 25/01/2016, 16:03
RaulArmando
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Indicador mediante php y mysql

Cita:
Iniciado por juancaalbarracin Ver Mensaje
Bueno se me ocurre que crees clases que te den los fondos de la celda que deseas. algo como:
Código CSS:
Ver original
  1. .verde {
  2.     background-color:#090;
  3. }
  4. .rojo{
  5.     background-color:#F00;
  6. }
  7. .amarillo{
  8.     background-color:#FF0;
  9. }
Luego de esto solo deberas comparar y asignar tu clase:

Código PHP:
Ver original
  1. $hcita= strtotime($consulta['Hsalida']);
  2. $hsalida = strtotime($consulta['Hcita']);
  3. $hactual=date("H:i");
  4.  
  5. if( $hactual > $hcita ) {
  6.     $clase="amarillo";
  7.     if( $hactual > $hsalida ) {
  8.           $clase="rojo";
  9. } else {
  10.     $clase="verde";
  11. }
Ahora lo colocas en la celda que deseas:

Código HTML:
Ver original
  1. <td class="<?php echo $clase?>">El mensaje</td>
Y creo que estará listo
Sigo sin poder hacer que cambie de color. No tengo idea si es por el strtotime porque se pone de color verde, en el else.

<!DOCTYPE html>
<head>
<title>Vista</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
include 'conexion.php';
$server = "localhost";
$user = "root";
$pass = "";
$bd = "bus";
$conexion = mysqli_connect($server, $user, $pass, $bd) or die ("Error en la conexión");

//CÓDIGO PARA ORDENAR LA TABLA DE FORMA DESCENDENTE
$consulta = mysqli_query($conexion, "SELECT * from datos ORDER BY id DESC") or die("Error al consultar");

echo "<table border=1px>";
echo "<th>REGISTRO ID</th> <th>NOMBRE DEL CODUCTOR</th> <th>N. AUTOBUS</th> <th>ORIGEN</th> <th>DESTINO</th> <th>CLIENTE</th> <th>FECHA DE SALIDA</th> <th>HORA DE SALIDA</th> <th>HORA DE CITA</th> <th>EVENTO</th>";

//WHILE QUE PERMITE MOSTRAR LAS CONSULTAS UNA TRAS OTRA
while($arreglo = mysqli_fetch_array($consulta))
{
echo "<tr>";
echo "<td>".$arreglo['id']."</td>";
echo "<td>".$arreglo['nombre']."</td>";
echo "<td>".$arreglo['autobus']."</td>";
echo "<td>".$arreglo['origen']."</td>";
echo "<td>".$arreglo['destino']."</td>";
echo "<td>".$arreglo['cliente']."</td>";
echo "<td>".$arreglo['fSalida']."</td>";
echo "<td>".$arreglo['hSalida']."</td>";
echo "<td>".$arreglo['hCita']."</td>";

//VARIABLES PARA LA HORA
$hCita = strtotime($arreglo['hSalida']);
$hSalida = strtotime($arreglo['hSalida']);
$hActual = date("H:i");

//ESTE ES EL CÓDIGO QUE ME DIERON DE EJEMPLO
if($hActual < $hCita){
$clase = "amarillo";
if($hActual > $hCita){
$clase = "rojo";
}else{
$clase = "verde";
}
}

//Este if ayuda a mostrar la bandera en caso de que en el radiobutton se seleccione la opción de "Prioritario".
if($arreglo['opcion'] == ('Prioritario')){
echo "<td class='$clase'>" .$arreglo['opcion']. "<img src='flag.png'>" . "</td>";
}//IF
else{
echo "<td class='$clase'>" .$arreglo['opcion'] . "</td>";
}//ELSE
echo "</tr>";

//HEADER PARA ESTAR REFRESCANDO LAS CONSULTAS
header('refresh:3; url=vista.php');
}//WHILE

mysqli_close($conexion);
echo "</table>";
?>
<br><input name="button" type="button" onclick="window.close();" value="Cerrar" />
</body>
</html>