Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/03/2012, 10:37
Avatar de repara2
repara2
 
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Cambiar el color de las celdas de una tabla

Código PHP:
Ver original
  1. <?php
  2.  
  3. ini_set("display_errors", 1);
  4. if(isset($_GET['restart']))
  5. {
  6.     header("Location: ".basename($_SERVER['PHP_SELF'])."");
  7. }
  8. if(!isset($_SESSION['tb']))
  9. {
  10.     $_SESSION['tb']=array();
  11. }
  12.  
  13. if(!isset($_SESSION['color_actual']))
  14. {
  15.     $_SESSION['color_actual']="white";
  16. }
  17.  
  18.  
  19. if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='POST')
  20. {
  21.     echo "la peticion es POST";
  22.     $_SESSION['f']=$_POST['filas'];
  23.     $_SESSION['c']=$_POST['columnas'];
  24.  
  25.     echo"<br>".$_SESSION['f']." filas";
  26.     echo"<br>".$_SESSION['c']." columnas";
  27.  
  28. }
  29. if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='GET')
  30. {
  31.     if(isset($_GET['color']))
  32.     {
  33.         $_SESSION['color_actual']=$_GET['color'];
  34.     }
  35.  
  36.     if(isset($_GET['fila']) && isset($_GET['columna']))
  37.     {
  38.         $f= $_GET['fila'];
  39.         $c= $_GET['columna'];
  40.     }
  41. }
  42. ?>
  43. <html>
  44. <head></head>
  45. <body>
  46.  
  47. <form method="post" action="">
  48. <p>Filas: <input type="number" name="filas" /></p>
  49. <p>Columnas: <input type="number" name="columnas" /></p>
  50. <p><input type="submit" name="submit" /></p>
  51. </form>
  52.  
  53. <table border="1">
  54. <?php for($i=0;$i<$_SESSION['f'];$i++): ?>
  55.     <tr>
  56.     <?php for($x=0;$x<$_SESSION['c'];$x++): ?>
  57.         <td style="background-color:<?php echo ($f==$i && $c == $x)?$_SESSION['color_actual']:""; ?>;"><a
  58.             href="?fila=<?php echo $i ?>&columna=<?php echo $x ?>"> <?php echo"$i-$x"; ?></a></td>
  59.             <?php endfor; ?>
  60.     </tr>
  61.     <?php endfor; ?>
  62. </table>
  63.  
  64. <ul>
  65.     <li><a href="?color=red">Rojo</a></li>
  66.     <li><a href="?color=green">Verde</a></li>
  67.     <li><a href="?color=blue">Azul</a></li>
  68.     <li><a href="?restart=restart">Restart</a></li>
  69. </ul>
  70.  
  71. </body>
  72. </html>
__________________
Fere libenter homines, id quod volunt, credunt.