Foros del Web » Programando para Internet » PHP »

Problema con horario en php

Estas en el tema de Problema con horario en php en el foro de PHP en Foros del Web. Buenos dias chicos! Estoy realizando un proyecto en el cual tengo la siguiente idea: El usuario sube un archivo excel, y automaticamente tiene que salir ...
  #1 (permalink)  
Antiguo 23/03/2010, 05:07
 
Fecha de Ingreso: marzo-2010
Mensajes: 10
Antigüedad: 14 años, 1 mes
Puntos: 0
Exclamación Problema con horario en php

Buenos dias chicos!

Estoy realizando un proyecto en el cual tengo la siguiente idea:

El usuario sube un archivo excel, y automaticamente tiene que salir un "horario" con cada celda pintada de un color segun sea el valor que hay en la tabla sql.

Lo que tengo...
El excel lo he subido al mysql pero ahora no tengo ni idea de como sacar esos datos en una tabla php para que la "pinte".
Lo que he intentado es esto:

Código:
<?php require_once('Connections/localhost.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_localhost, $localhost);
$query_Lunes = "SELECT hoja1.ACTIVIDAD FROM hoja1 WHERE hoja1.DIA = 'Lunes' ORDER BY hoja1.HORA";
$Lunes = mysql_query($query_Lunes, $localhost) or die(mysql_error());
$row_Lunes = mysql_fetch_assoc($Lunes);
$totalRows_Lunes = mysql_num_rows($Lunes);

mysql_select_db($database_localhost, $localhost);
$query_Lunes2 = "SELECT hoja1.SALA, hoja1.HORA, hoja1.ACTIVIDAD FROM hoja1 WHERE hoja1.DIA = 'Lunes' ORDER BY hoja1.HORA";
$Lunes2 = mysql_query($query_Lunes2, $localhost) or die(mysql_error());
$row_Lunes2 = mysql_fetch_assoc($Lunes2);
$totalRows_Lunes2 = mysql_num_rows($Lunes2);

mysql_select_db($database_localhost, $localhost);
$query_HORA = "SELECT DISTINCT hoja1.HORA FROM hoja1 ORDER BY hoja1.HORA ASC";
$HORA = mysql_query($query_HORA, $localhost) or die(mysql_error());
$row_HORA = mysql_fetch_assoc($HORA);
$totalRows_HORA = mysql_num_rows($HORA);
?><!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>Documento sin título</title>
</head>

<body>
<table>
  <tr>
    <td>HORA</td>
    <td><p>SALA</p></td>
    <td>LUNES</td>
    <td>MARTES</td>
    <td>MIERCOLES</td>
    <td>JUEVES</td>
    <td>VIERNES</td>
    <td>SABADO</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_HORA['HORA']; ?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <?php } while ($row_Lunes = mysql_fetch_assoc($Lunes)); ?>
</table>
<?php do { ?>
<?php } while ($row_Lunes = mysql_fetch_assoc($Lunes)); ?>
</body>
</html><?php
mysql_free_result($Lunes);

mysql_free_result($Lunes2);

mysql_free_result($HORA);
?>
Lo que no consigo es que me salga esto:
---------------------------------------------------------------------------------
Hora | Sala | Lunes | Martes | Miercoles | Jueves | Viernes | Sabado
--------------------------------------------------------------------------------------

08:00 | SALA1| act1 | actx.........................................

Sabeis? Entonces, con lo que he intentado si que me salen las actividades pero claro.. no se corresponden a la hora . Las columnas no tienen ninguna relacion entre ellas...

He encontrado cosas por la web pero todo son sobre calendarios semanales donde crean bucles y cosas "raras" para averiguar la fecha actual y tal.
Pero yo no necesito eso, solo que me muestre los datos en una tabla y que despues me lo pinte segun un valor que hay en la bd.

Mil gracias :)

Última edición por kukinogi; 23/03/2010 a las 09:57
  #2 (permalink)  
Antiguo 23/03/2010, 08:17
Avatar de Marvin
Colaborador
 
Fecha de Ingreso: febrero-2005
Ubicación: global $Chile->Santiago;
Mensajes: 1.991
Antigüedad: 19 años, 2 meses
Puntos: 81
Respuesta: Problema con horario en php

No sera mejor sacar todos los resultados de la base de datos y luego hacer los filtros por dia/hora?...

O sea...
Código PHP:
if($row['Dia'] == "Lunes"){
//aca todo lo que va para el lunes.
}
if(
$row['Dia'] == "Martes"){
//aca todo lo que va para el martes.
}
//etc... 
Tambien puedes filtrar las horas y etc.

Verifica si la hora se esta guardando en formato HH:MM:SS en ese caso tienes que utilizar alguna funcion que lo ponga en ese formato como por ejemplo:
Código PHP:
if($row['Hora'] >= '08:00:00'){ 
Suerte!
__________________
El que dice "Solo sé que nada sé", esta asumiendo que sabe algo.
Lea las FAQ's!
  #3 (permalink)  
Antiguo 23/03/2010, 09:55
 
Fecha de Ingreso: marzo-2010
Mensajes: 10
Antigüedad: 14 años, 1 mes
Puntos: 0
Respuesta: Problema con horario en php

Mmmm.. Eso donde lo pongo?
En la tabla??
Perdona, pero no lo entiendo.

Gracias por la respuesta ;)
  #4 (permalink)  
Antiguo 23/03/2010, 10:45
Avatar de Marvin
Colaborador
 
Fecha de Ingreso: febrero-2005
Ubicación: global $Chile->Santiago;
Mensajes: 1.991
Antigüedad: 19 años, 2 meses
Puntos: 81
Respuesta: Problema con horario en php

Tienes que armar la tabla segun los datos que vas obteniendo... algo como esto:
Código PHP:
$sql "SELECT ACTIVIDAD FROM hoja1 ORDER BY HORA";
$resultados mysql_query($sql);
$html '
<table>
<tr>
    <td>HORA</td>
    <td><p>SALA</p></td>
    <td>LUNES</td>
    <td>MARTES</td>
    <td>MIERCOLES</td>
    <td>JUEVES</td>
    <td>VIERNES</td>
    <td>SABADO</td>
</tr>'
;
while(
$datos=mysql_fetch_array($resultados)){
$html .= '
<tr>
    <td>'
.$datos['HORA'].'</td>
    <td>'
.$datos['SALA'].'</td>
    <td>'
.$datos['DIA'] == "Lunes"?1:0.'</td>
    <td>'
.$datos['DIA'] == "Martes"?1:0.'</td>
    <td>'
.$datos['DIA'] == "Miercoles"?1:0.'</td>
    <td>'
.$datos['DIA'] == "Jueves"?1:0.'</td>
    <td>'
.$datos['DIA'] == "Viernes"?1:0.'</td>
    <td>'
.$datos['DIA'] == "Sabado"?1:0.'</td>
</tr>'
;
}
$html .= '
</table>'
;
print 
$html
Esto:
Código PHP:
$datos['DIA'] == "Sabado"?1:
Pregunta si $datos['DIA'] es igual a "Sabado" y de ser asi se va a mostrar un 1, en caso contrario mostrara un 0.

Si quieres reemplazar eso con texto puedes ponerlo entre comillas.

Suerte!
__________________
El que dice "Solo sé que nada sé", esta asumiendo que sabe algo.
Lea las FAQ's!

Etiquetas: horario
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:07.