Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/02/2012, 19:27
Avatar de function
function
 
Fecha de Ingreso: abril-2010
Mensajes: 278
Antigüedad: 14 años
Puntos: 13
Pregunta Calendario semanal y Mysql

Amigos, estoy atascado con el while de mysql, no se como sacar los datos sin que se me multipliquen tantos espacios. tengo esto:
Código PHP:
Ver original
  1. <?php
  2. // I create the db connection
  3. $conn = mysql_connect('host', 'user', 'pass') or die (mysql_error());
  4. //testing connection
  5. if (!$conn){
  6.     die('No se conecta dando un error el cual es: '.mysql_error());
  7. }
  8. //selecting a db
  9. mysql_select_db('calendar', $conn) or die('No se encontro la BD dando un error el cual es: '.mysql_error());
  10.  
  11. //Selecting the Query from patients_control
  12. $sql = mysql_query("SELECT * FROM reuniones ORDER BY id ASC");
  13.  
  14. //Hacemos el if/else para ver si se han seteado en la url mediante GET los parametros wk = semana
  15. $week = isset($_GET['wk']) ? $_GET['wk'] : '';
  16. //Si es lunes calculamos a partir de la fecha actual
  17. if(date('w') == 1) {
  18.     //verificamos si la variable $week no esta vacia
  19.     if(!empty($week)){
  20.         //Si no esta vacia agregamos el valor de $week asignandole la marca de tiempo UNIX
  21.         $ul = strtotime("$week week", time());
  22.     } else {
  23.         //Si esta vacia simplemente le damos la marca de tiempo UNIX
  24.         $ul = time();
  25.     }
  26. } else {
  27.     if(!empty($week)){
  28.         $ul = strtotime("last monday $week week");
  29.     } else {
  30.         $ul = strtotime('last monday');
  31.     }
  32. }
  33. //Array con los dias de la semana
  34. $dias_semana = array('Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo');
  35. //Array Horas del dia
  36. $hours = array("6:00", "7:00", "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00");
  37. ?>
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  39. <html xmlns="http://www.w3.org/1999/xhtml">
  40. <head>
  41. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  42. <title>Calendar Sample</title>
  43. <link rel="shortcut icon" href="icon" />
  44. <link href="styles.css" rel="stylesheet" type="text/css" />
  45. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  46. <script language="javascript" type="text/javascript">
  47. $(document).ready(function(){
  48.     var h = document.body.scrollHeight;
  49.     var nh = Math.round(h/18);
  50.     $('.tableheight').css({'height':h});
  51.     $('.trheight').css({'height':nh});
  52.    
  53. });
  54. </script>
  55. </head>
  56.  
  57. <body>
  58. <!-- Table: General -->
  59. <table class="tableheight" width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ddd"   >
  60.     <tr>
  61.         <th class="trheight"><a href="index.php?wk=<?php echo $week-1; ?>">Prev</a>-<a href="index.php?wk=<?php echo $week+1; ?>">Next</a></th>
  62.         <?php
  63.         //Bucle para mostrar los 7 dias de la semana
  64.         for($i=0;$i<7;$i++){
  65.             //Sumamos días a la fecha del lunes actual
  66.             $sd = strtotime("+$i day", $ul);
  67.             //comprobamos si la fecha del bucle es la fecha actual
  68.             if(date('d', $sd) === date('d')) { 
  69.                 //colocamos el dia actual en rojo y ponemos el array para mostrar los dias en español
  70.                 echo '<th width="12.5%"><font color="red">'.$dias_semana[$i].', '.date("d", $sd).'</font></th>';
  71.             } else {
  72.                 //colocamos el el resto de los dias en gris y ponemos el array para mostrar los dias en español
  73.                 echo '<th width="12.5%"><font color="black">'.$dias_semana[$i].', '.date("d", $sd).'</font></th>';
  74.             }
  75.         }
  76.        
  77.         //hago los dias
  78.         for($h=0; $h < count($hours); $h++) {
  79.             echo '<tr><th>';
  80.             echo $hours[$h];
  81.             echo '</th>';
  82.             for($y=0;$y<7;$y++){
  83.  
  84.  //>>>>>>>>>>> AQUI CREO QUE DEBERIA IR EL WHILE PERO NO ME FUNCIONA, AYUDA PORFA
  85.  
  86.                 $xxx = strtotime("+$y day", $ul);
  87.                 echo '<td width="12.5%"><font color="black">'.date("Y-m-d", $xxx).'</font></td>';
  88.             }
  89.             echo '</tr>';
  90.         }
  91.         ?>
  92.     </tr>
  93. </table>
  94. <!-- Table: General -->
  95. </body>
  96. </html>

Gracias
__________________
~# echo Hemos logrado la independencia, pero no la libertad >> SimonBolivar