Ver Mensaje Individual
  #6 (permalink)  
Antiguo 16/07/2012, 16:17
racba
 
Fecha de Ingreso: diciembre-2004
Mensajes: 21
Antigüedad: 19 años, 5 meses
Puntos: 3
Respuesta: Arreglar tabla horario; mostrar asignaturas en filas según día

Olvide poner el codigo completo, asi que aqui esta para que puedas probarlo:
Código PHP:
Ver original
  1. <?php      
  2. /*$inf = array(); //declaramos un arreglo donde guardamos los registros encontrados
  3. while($d = mysql_fetch_array($dat)) {
  4.  $inf[] = $d; //Buscamos los datos almacenados y los asignados al arreglo para poderlos manipular a consideración nuestra
  5. }*/
  6. $lunes = array('dia'=> 1, 'h_entrada'=>'07:00:00', 'h_salida'=>'10:00:00','materia'=>'QUIMICA','grado'=>'1','seccion'=> '1','aula'=> 'A');
  7. $martes =array('dia'=> 2,'h_entrada'=>'08:00:00', 'h_salida'=>'10:00:00','materia'=>'FISICA','grado'=>'1','seccion'=> '2','aula'=> 'B');
  8. $miercoles = array('dia'=> 3,'h_entrada'=>'09:00:00', 'h_salida'=>'12:00:00','materia'=>'','grado'=>'2','seccion'=> '1','aula'=> 'C');
  9. $jueves = array('dia'=> 4,'h_entrada'=>'10:00:00', 'h_salida'=>'13:00:00','materia'=>'LENGUA','grado'=>'2','seccion'=> '2','aula'=> 'D');
  10. $viernes = array('dia'=> 5,'h_entrada'=>'01:00:00', 'h_salida'=>'14:00:00','materia'=>'GEOGRAFIA','grado'=>'3','seccion'=> '1','aula'=> 'E');
  11.  
  12. $dia = array(1 => ($lunes), 2 => ($martes), 3 => ($miercoles), 4 => $jueves, 5 => $viernes);
  13. $inf[0] = $dia["1"];
  14. $inf[1] = $dia["2"];
  15. $inf[2] = $dia["3"];
  16. $inf[3] = $dia["4"];
  17. $inf[4] = $dia["5"];
  18. $inf[5] = $dia["1"];
  19. $inf[6] = $dia["2"];
  20. $inf[7] = $dia["3"];
  21. $inf[8] = $dia["4"];
  22. $inf[9] = $dia["5"];
  23.  
  24.     echo "<table width='800px' border='1' align='center'cellpadding='2' cellspacing='0'>";
  25.        echo "<tr width='780px'>";
  26.          echo "<td width='150px' bgcolor='#ECE9D8'><div align='center'>LUNES</div></td>";
  27.          echo "<td width='150px' bgcolor='#ECE9D8'><div align='center'>MARTES</div></td>";
  28.          echo "<td width='150px' bgcolor='#ECE9D8'><div align='center'>MIERCOLES</div></td>";
  29.          echo "<td width='150px' bgcolor='#ECE9D8'><div align='center'>JUEVES</div></td>";
  30.          echo "<td width='150px' bgcolor='#ECE9D8'><div align='center'>VIERNES</div></td>";
  31.        echo "</tr>";
  32.        echo "<tr width='780px' border='1'cellpadding='1' cellspacing='1'>";
  33.        
  34. //**********PRIMERA FILA DE DATOS *********
  35. for ($i=1;$i<=5;$i++) {//con este for le damos el valor a las horas en una columna      
  36.     for ($j=0;$j<=4;$j++) {//con este recuperamos la informacion del arreglo y la llamamos el registro que nos interesa
  37.        
  38.        if ($inf[$j]['dia'] == $i)  
  39.          {//mostramos el valor
  40.        //echo "</tr>";
  41. echo "<td style='width:140px; background:#E3E9F1'>";
  42. if($inf[$j]['h_entrada']==''){ echo "LIBRE";}else {echo $inf[$j]['h_entrada']." - ";}
  43. if($inf[$j]['h_salida']==''){ echo "LIBRE";}else {echo $inf[$j]['h_salida']."<br>";}
  44. if($inf[$j]['materia']==''){ echo "LIBRE";}else {echo $inf[$j]['materia']."<br>";}
  45. if($inf[$j]['grado']==''){ echo "LIBRE";}else {echo $inf[$j]['grado']." - ";}
  46. if($inf[$j]['seccion']==''){ echo "LIBRE";}else {echo $inf[$j]['seccion']." - ";}
  47. if($inf[$j]['aula']==''){ echo "LIBRE";}else { echo $inf[$j]['aula']."";}
  48. echo "</td>";
  49.          }        
  50.     }    
  51. }
  52. //*************FIN PRIMERA FILA *****************
  53.  
  54. //*********** AGREGAMOS UN CIERE DE TAG Y UN INICIO**********
  55. echo "</tr>";
  56.          echo "<tr width='780px' border='1'cellpadding='1' cellspacing='1'>";
  57.          
  58.  //**********SEGUNDA FILA DE DATOS *********
  59.        
  60. for ($i=1;$i<=5;$i++) {//con este for le damos el valor a las horas en una columna      
  61.     for ($j=5;$j<=9;$j++) {//con este recuperamos la informacion del arreglo y la llamamos el registro que nos interesa
  62.        
  63.        if ($inf[$j]['dia'] == $i)  
  64.          {//mostramos el valor
  65.        //echo "</tr>";
  66. echo "<td style='width:140px; background:#E3E9F1'>";
  67. if($inf[$j]['h_entrada']==''){ echo "LIBRE";}else {echo $inf[$j]['h_entrada']." - ";}
  68. if($inf[$j]['h_salida']==''){ echo "LIBRE";}else {echo $inf[$j]['h_salida']."<br>";}
  69. if($inf[$j]['materia']==''){ echo "LIBRE";}else {echo $inf[$j]['materia']."<br>";}
  70. if($inf[$j]['grado']==''){ echo "LIBRE";}else {echo $inf[$j]['grado']." - ";}
  71. if($inf[$j]['seccion']==''){ echo "LIBRE";}else {echo $inf[$j]['seccion']." - ";}
  72. if($inf[$j]['aula']==''){ echo "LIBRE";}else { echo $inf[$j]['aula']."";}
  73. echo "</td>";
  74.          }  
  75.     }    
  76. }
  77. //*************FIN SEGUNDA FILA *****************
  78.  
  79.  echo "</tr>";
  80.    echo "</table>";
  81.  
  82. ?>