Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/08/2014, 03:22
elitown87
 
Fecha de Ingreso: junio-2014
Mensajes: 101
Antigüedad: 9 años, 10 meses
Puntos: 0
Respuesta: vaciar sesiones en cada iteración

He utilizado el unset pero no se si lo he puesto en el lugar correcto; lo que hace es ir almacenando y mostrando el resultado de ntodas las consultas que voy haciendo...

El código del .php en el que defino la sesión es este:

Código PHP:
Ver original
  1. <?php
  2.         session_start();
  3. ?>
  4.  
  5. <html>
  6.  
  7. <HEAD>
  8.     <LINK REL="stylesheet" HREF="css.css" TYPE="text/css">
  9.     <meta charset="utf-8"/>
  10. </HEAD>
  11.  
  12. <H2 align = "center">Insertar contenido por nombre de empresa</H2>
  13. <form align = "center" name = "form1" method = "post" action = "buscadorgrupo.php">
  14. <br><br>
  15. Empresa:
  16. <input align = "center" name = "busca" type = "text" autocomplete = 'off'>
  17. <input type = "submit" name = "submit" value = "Buscar">
  18. <br><br>
  19. <br><br>
  20. </form>
  21.  
  22. <body>
  23.  
  24. <?php
  25.  
  26.     //recogemos el valor que se mete en el campo de texto mediante post
  27.     $busca = $_POST['busca'];
  28.  
  29.         //Aquí va la conexión a la BBDD
  30.            
  31.     if($busca!=""){
  32.  
  33.         $busqueda = "SELECT * FROM dispositivos WHERE nombre_de_la_empresa LIKE '%$busca%'";
  34.         $result = mysql_query($busqueda);
  35.  
  36.             echo "<table align = 'center' cellspacing='10' cellpadding='10' border='3'>";
  37.             echo "<tr>";
  38.    
  39.                 echo "<td>";
  40.                 echo "<table align = 'center' cellspacing='2' cellpadding='2' border='1'>";
  41.                 echo "<TH>Id</TH>";
  42.             echo "<TH>Dispositivos</TH>";
  43.             echo "<TH>Fecha de creación</TH>";
  44.  
  45.             while($fila = mysql_fetch_array($result)){
  46.  
  47.                 echo "<tr>";
  48.  
  49.                 echo "<td align = 'center'>$fila[id]</td>";
  50.                 echo "<td align = 'center'>$fila[Dispositivos]</td>";
  51.                 echo "<td align = 'center'>$fila[nombre_de_la_empresa]</td>";
  52.  
  53.                 echo "</tr>";
  54.  
  55.             }
  56.                
  57.                 echo "</table>";
  58.             echo "</td>";
  59.  
  60.  
  61.             echo "<td>";
  62.                 echo "<table align = 'center' cellspacing='2' cellpadding='2' border='1'>";
  63.                 echo "<TH>Grupos</TH>";
  64.                
  65.                 include("grupos.php");
  66.                 $Con = new grupos();
  67.                 $Con -> hacer_grupos();        
  68.                
  69.                 echo "</table>";
  70.             echo "</td>";  
  71.  
  72.             echo "</tr>";
  73.             echo "</table>";
  74.  
  75.             $_SESSION['buscar'] = $busca;
  76.  
  77.     }
  78.  
  79. //unset($_SESSION['buscar']);
  80.  
  81. ?>
  82.  
  83.  
  84. </body>
  85. </html>

El código del .php grupos.php, al que apunta el include es el siguiente:

Código PHP:
Ver original
  1. <?php
  2.         session_start();
  3. ?>
  4. <html>
  5. <head>
  6. <LINK REL="stylesheet" HREF="css.css" TYPE="text/css">
  7. <meta charset = "utf-8"/>
  8. </head>
  9. <body>
  10.  
  11. <?php
  12.     class grupos{
  13.         function hacer_grupos(){
  14.  
  15.             //Aquí va la conexion a la BBDD
  16.  
  17.             $busca = $_SESSION['buscar'];
  18.            
  19.             $busqueda = "SELECT * FROM dispositivos WHERE nombre_de_la_empresa LIKE '%$busca%'";
  20.             $result = mysql_query($busqueda);
  21.  
  22.             $busqueda2 = "SELECT nombre_grupo FROM grupos WHERE nombre_de_la_empresa LIKE '%$busca%'";
  23.             $result2 = mysql_query($busqueda2);
  24.    
  25.             while($fila = mysql_fetch_array($result)){
  26.  
  27.                 while($fila2 = mysql_fetch_array($result2)){
  28.  
  29.                     echo "<tr>";
  30.                     echo "<td align = 'center'>$fila2[nombre_grupo]</td>";
  31.                     echo "</tr>";
  32.                 }
  33.                
  34.             }
  35.         }
  36.     }
  37.  
  38. ?>
  39.  
  40. </body>
  41. </html>

Muchas gracias de nuevo!