Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/05/2006, 04:29
morpheux
 
Fecha de Ingreso: abril-2006
Mensajes: 14
Antigüedad: 18 años
Puntos: 0
Problema con variables de session que es un array

Os voy a poner el código, no esta muy otimizado pero bueno, como no sale bien tampoco quiero meterme a más hasta que supere la crisis.

Código PHP:
function push()
{
        
session_start();
        global 
$_CONT_BUTACAS$_BUTACAS$_SALA,$_HORA,$_FECHA,$_USUARIO,$_CINE;
        
//$arr_but=array();
        
$contenido="";
        if (
$_CONT_BUTACAS 9)
        {
            
$rep 0;
            for (
$i=0;$i<count($_BUTACAS);$i++)
            {
                if (
$_BUTACAS[$i]==$_REQUEST['id'])
                {
                    
$rep=1;
                }
            }
            if (
$rep == 0)
            {
                
$link=conectadb();
                
$pos=0;
                for (
$q=0;$q<count($_BUTACAS);$q++)
                {
                    
$pos=$q;
                }
                
$_BUTACAS[$pos+1]=$_REQUEST['id'];
                
$_CONT_BUTACAS$_CONT_BUTACAS 1;
                
$_SALA=$_REQUEST['sala'];
                
$_HORA=$_REQUEST['hora'];
                
$_FECHA=date("dmY");
                
$_USUARIO=$_REQUEST['user'];
                
$_CINE=$_REQUEST['cine'];
                
$sql="select * from prc_butaca where id_sala=".$_SALA;
                
$res=mysql_query($sql,$link) or die("<html>
                                                <head>
                                                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
                                                <link href=\"estilo.css\" rel=\"stylesheet\" type=\"text/css\">
                                                </head>
                                                    <body>
                                                    <br><br><br><br>
                                                    <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\" class=\"tableb\">
                                                    <tr><td>
                                                    <h3 align=\"center\">No se pudo completar la operación:"
.mysql_error()."<br></h3>
                                                    <h3 align=\"center\">No se puedo completar la operación:"
.$sql."<br></h3>
                                                    
                                                    </td></tr></table>
                                                </body>
                                            </html>"
);
                
$arr_but = array();
                while (
$but mysql_fetch_array($res,MYSQL_ASSOC))
                {
                    
$arr_but[]=$but['id'];
                }
                
$sql="select * from prc_sala where id=".$_SALA;
                
$resala=mysql_query($sql,$link) or die("<html>
                        <head>
                        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
                        <link href=\"estilo.css\" rel=\"stylesheet\" type=\"text/css\">
                        </head>
                            <body>
                            <br><br><br><br>
                            <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\" class=\"tableb\">
                            <tr><td>
                            <h3 align=\"center\">No se pudo completar la operación:"
.mysql_error()."<br></h3>
                            <h3 align=\"center\">No se puedo completar la operación:"
.$sql."<br></h3>
                            </td></tr></table>
                        </body>
                    </html>"
);
                
$dat_sala=mysql_fetch_array($resala,MYSQL_ASSOC);
                
$filas=$dat_sala['fila'];
                
$columnas=$dat_sala['columna'];
                
$contenido .="<html>
                            <head>
                            <title>Documento sin t&iacute;tulo</title>
                            <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
                            <link href=\"estilo.css\" rel=\"stylesheet\" type=\"text/css\">
                            </head>
                            
                            <body>
                            <table width=\"400\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tableb\">
                              <tr>
                                <td>"
;
                
$contenido .="<div style=\"padding-top:20px; padding-left:20px; padding-right:20px; padding-bottom:20px; background-color:#FFFFFF\">
                            <p align=\"center\" style=\"font-family:'Trebuchet MS', Verdana, Tahoma; font-size:10px; font-weight:bold; color:#000000\">Hoy::::Mañana::::Pasado Mañana &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{HORAS}</p>
                        </div>
                            <div style=\"padding-top:20px; padding-left:20px; padding-right:20px; padding-bottom:20px; background-color:#FFFFFF\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
;
                
$butid=reset($arr_but);
                for (
$i=1;$i<=$filas;$i++)
                {
                  
$contenido.="<tr>";
                    for(
$x=1;$x<=$columnas;$x++)
                     {
                        
$butid=current($arr_but);
                        
$sql="select * from prc_compran where id_butaca=".$butid." AND fecha= ".$_FECHA." AND hora=".$_HORA;
                        
$res=mysql_query($sql,$link) or die("<html>
                                                                <head>
                                                                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
                                                                <link href=\"estilo.css\" rel=\"stylesheet\" type=\"text/css\">
                                                                </head>
                                                                    <body>
                                                                    <br><br><br><br>
                                                                    <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"3\" class=\"tableb\">
                                                                    <tr><td>
                                                                    <h3 align=\"center\">No se pudo completar la operación:"
.mysql_error()."<br></h3>
                                                                    <h3 align=\"center\">No se puedo completar la operación:"
.$sql."<br></h3>
                                                                    </td></tr></table>
                                                                </body>
                                                            </html>"
);
                        
// recorremos aqui todo el array de las butacas, y comprobamos que alguno de ellos no sea igual que la butaca que tenemos ahora en butid, si es asi
                        // en la parte del if diferenciaremos entre libre y por el usuario, si la variable esta a 0 tal y sino pascual
                        
$bingo=0;
                        
$aux=$butid;
                        for (
$m=1;$m<=count($_BUTACAS);$m++)
                        {
                            
//echo ($_BUTACAS[$m]. " == " . $butid." - ". $_REQUEST['id'] );
                            
if ($_BUTACAS[$m]==$aux)
                            {
                                
$bingo=1;
                            }
                        }
                        
//die($aux. " - ". $_BUTACAS[$m]);
                        //die("FIN");
                        
if (!mysql_num_rows($res))
                        {    
                                if (
$bingo==1)
                                {
                                    
$contenido.= "<td width=\"32\" height=\"30px\"><a href=\"comprar.php?id=".$butid."&cine=".$_CINE."&sala=".$_SALA."&hora=".$_HORA."&acc=2&user=".$_USUARIO."\"><img src=\"imagenes/butaca_usu.jpg\" border=\"0\"></a></td>";
                                }
                                else
                                {
                                    
$contenido.= "<td width=\"32\" height=\"30px\"><a href=\"comprar.php?id=".$butid."&cine=".$_CINE."&sala=".$_SALA."&hora=".$_HORA."&acc=1&user=".$_USUARIO."\"><img src=\"imagenes/butaca_libre.jpg\" border=\"0\"></a></td>";
                                }
                        }
                        else
                        {
                                
$contenido.= "<td width=\"32\" height=\"30px\"><img src=\"imagenes/butaca_ocu.jpg\" border=\"0\"></td>";
    
                        }
                        
next($arr_but);
                     }
                  
$contenido.="</tr>";
                }        
              
            
$contenido.="</table>
            <a>Continuar</a>
            </div>
            </td>
              </tr>
            </table>
            </body>
            </html>"
;
            echo 
$contenido;    
            }
            else
            {
                
            }
        }
        else
        {
        }

El problema está en que en $_BUTACAS que esta declarada como session_register("_BUTACAS") en otro script no hay manera que se le incluya en el array más de un elemento.

Es decir, que cada vez que entra solo tiene un valor, en vez de acumularlos en el array

Es en esta parte:

for ($q=0;$q<count($_BUTACAS);$q++)
{
$pos=$q;
}
$_BUTACAS[$pos+1]=$_REQUEST['id'];

Esto se podria hacer directamente con un count, pero estaba comprobando cosillas

Pero es que además descubro que tampoco me funciona el contador de butacas, por tanto las variables de sesion, las debo estar haciendo o llamando mal porque no me funcionan ninguna, ya que el contador da igual lo que haga que siempre es 1.

LAs variables de sesion las registro con session_register("VARIABLE") y las llamo como $VARIABLE.

A ver si me podeis decir donde tengo el error. qeu estoy atascadisimo

MUCHAS GRACIAS POR ADELANTADO