Ver Mensaje Individual
  #9 (permalink)  
Antiguo 25/01/2012, 14:16
Crea
 
Fecha de Ingreso: abril-2008
Mensajes: 50
Antigüedad: 16 años
Puntos: 3
Respuesta: Como armar variable para tomar otro dato

Ok, ya había intentado hacer eso en cuanto al color y funcionaba en carro.php pero en la página anterior me mostraba el "id", ahorita que hice el cambio ya me pone el color en las 2 páginas, o sea: ¡¡problema resuelto!!

Vamos con lo demás, te pongo el código y te explico el problema:

Código PHP:
<?php
            $id 
$_GET['id'];
            
            
$resultado mysql_query("SELECT id, producto, precio FROM productos WHERE id='1'")or die( "Error en query: $sql, el error  es: " mysql_error() );
            
            
            
$consulta "select id, color from color";
            
$result=mysql_query($consulta);    
            
            echo 
"<div class=verproductos>";
            echo 
"<table style=border:1px solid #333333>
                <tr class=titulo>
                    <th style='display:none'>ID</th>
                    <th class='desc_largo'>Producto</th>
                    <th style='width:50px;text-align:center'>Color</th>
                    <th style='width:100px;text-align:center'>Precio</th>
                    <th style='width:50px;text-align:right'>Acción</th>
                    
                </tr>"
;
                
            while (
$productos mysql_fetch_array($resultado)) { 
                echo 
"<tr class='borde_tabla'><td style='display:none'>" $productos['id'] . "</td>";    
                echo 
"<td>" $productos['producto'] . "</td>";    
                
                
?>
                <td>
                <?php 
                
if(isset($_SESSION['carro'][$productos['id']])){ ?>
                <form method="post" action="carro.php?id=<?php $productos['id']&$productos['precio']; ?>&action=add">
                <?php }else{?>
                <form method="post" action="carro.php?id=<?php $productos['id']&$productos['precio']; ?>&action=add">
                <?php }?>
*
*                
                <select name="color">
                <option value="">Color</option>
*
                <?php
                
while($fila=mysql_fetch_row($result)){
                echo 
"<option value='".$fila['1']."'>".$fila['1']."</option>";
                }
                
?>
*
                </select>
*                
                <?php 
                
echo "<td style='text-align:right'>$" $productos['precio'] . "  </td>";
                
?>
                <td>
                <?php
                
if(isset($_SESSION['carro'][$productos['id']])){ ?>
                <input name="" type="image" src="img/add_carro.png" width="50" height="50">
                <?php }else{?>
                <input name="" type="image" src="img/add_carro.png" width="50" height="50">
                <?php }?>
*
                </form>
                </td>
                <?
                
                
/*echo "<td style='text-align:right'>
                                <a href='carro.php?id=" . $productos['id'] . "&action=";
                                
                                if (isset($_SESSION['carro'][$productos['id']])){
                                    //echo "remove' alt='Eliminar del carro'><img src='img/remove_carro.png' width='48' height='48' alt='Eliminar del                                 carro' title='Añadir producto al carrito'>";
                                    echo "removeProd' alt='Eliminar del carro'><img src='img/remove_carro.png' width='48' height='48' alt='Eliminar del carro' title='Añadir producto al carrito'>";
                                }
                                else
                                    echo "add' alt='Añadir al carro'><img src='img/add_carro.png' width='48' height='48' alt='Añadir al carrito' title='Añadir producto al carrito'>";
                                    
                                
                echo "</a></td>";*/
                 
            
}
            
            
            
            
                            
            
//cerramos la etiqueta tabla
            
echo "</table>";
            
        
                
/*echo $_SESSION["totalcoste"] . "<br>";
                echo $_SESSION["cantidadTotal"] . "<br>";*/
            
            
echo "</div>";
        
?>
Esto es en la página http://www.dejavu.com.mx/sim_nat_1.php , de aquí se manda a carro.php que tiene este código:

Código PHP:
<?php
            
            
if (isset($_GET['id']))
                
$id $_GET['id'];
            else
                
$id 1;
            
            if (isset(
$_GET['action']))
                
$action $_GET['action'];
            else
                
$action "empty";
    
    
            switch(
$action){
            
                case 
"add":
                    if(isset(
$_SESSION['carro'][$id]))
                        
$_SESSION['carro'][$id]++;
                    else
                        
$_SESSION['carro'][$id]=1;
                break;
                
                case 
"remove":
                    if(isset(
$_SESSION['carro'][$id]))
                    {
                        
$_SESSION['carro'][$id]--;
                        if(
$_SESSION['carro'][$id]==0)
                            unset(
$_SESSION['carro'][$id]);
                    }
                    
                break;
                case 
"removeProd":
                    if(isset(
$_SESSION['carro'][$id])){
                        unset(
$_SESSION['carro'][$id]);
                    }
                break;
                
                case 
"mostrar":
                    if(isset(
$_SESSION['carro'][$id])){
                        continue;
                    }
                break;
                
                case 
"empty":
                    unset(
$_SESSION['carro']);
                
                break;
                        
                
            }

            
/*MOSTRAR Carro*/
            /*echo "<pre>";
                print_r($_SESSION);
              echo "</pre>";

              echo "CANTIDAD: " .    $_SESSION['carro'][$id] . "<br>";
              echo "ID      : " . $id . "<br>";
            */
            
            
if(isset($_SESSION['carro'])){
                echo 
"<table border=0 cellspacing=5 cellpadding=3 width='500'>";
                
$totalcoste 0;
                
//Inicializamos el contador de productos seleccionados.
                
$xTotal 0;
                
                echo 
"<tr>";
                    echo 
"<td>Producto</td>";
                    echo 
"<td>Color</td>";
                    echo 
"<td>Cantidad</td>";
                    echo 
"<td>Acción</td>";
                    echo 
"<td colspan=2 align=right>Total</td>";
                echo 
"</tr>";
                echo 
"<tr><td colspan=5><hr></td></tr>";
    
                
                foreach(
$_SESSION['carro'] as $id => $x){
                    
$resultado mysql_query("SELECT id, producto, precio FROM productos WHERE id=$id");
                    
$mifila mysql_fetch_array($resultado);
                    
                    
                    
$id $mifila['id'];
                    
$producto $mifila['producto'];
                     
                    
//acortamos el nombre del producto a 40 caracteres
                    
$producto substr($producto,0,40);
                    
                    
$precio $mifila['precio'];
                    
//Coste por artículo según la cantidad elegida
                    
$coste $precio $x;
                    
//Coste total del carro
                    
$totalcoste $totalcoste $coste;
                    
//Contador del total de productos añadidos al carro
                    
$xTotal $xTotal $x;
                    
                    echo 
"<tr>";
                    echo 
"<td align='left'> $_POST[id] </td>";
                    echo 
"<td align='left'> $_POST[color]  </td>";
                    echo 
"<td align='center'>$x</td>";
                    
                    echo 
"<td align='left'>";
                    echo 
"<a href='carro.php?id="$id ."&action=add'><img src='img/aumentar.png' style='padding:0 0px 0 5px;' alt='Aumentar cantidad' /></a>";
                    
//Controlamos el display para cuando se vaya a eliminar el producto del carro o bien
                    //se vaya a reducir la cantidad.
                    //if ($x > 1)
                        
echo "<a href='carro.php?id="$id ."&action=remove'><img src='img/restar.png' alt='Reducir cantidad' /></a>";
                    
//else
                        
echo "<a href='carro.php?id="$id ."&action=removeProd'><img src='img/eliminar.png' alt='Reducir cantidad' /></a></td>";
                    
                    echo 
"<td align='right'> = </td>";
                    echo 
"<td align='right' style='margin-left:10px'>$$coste ";
                    echo 
"</tr>";
                }
                echo 
"<tr><td colspan='5'><hr></td></tr>";
                echo 
"<tr>";
                echo 
"<td align='right' colspan='4'><b><br>Total = </b></td>";
                echo 
"<td align='right'><b><br>$ $totalcoste </b> </td>";
                echo 
"</tr>";
                
//BOTON COMPRAR
                
echo "<tr>";
                echo 
"<td align='right' colspan='5'>
                        <a href='comprar.php'><input type='button' value='finalizar compra' /></a>
                </td>"
;
                echo 
"</tr>";
                
                echo 
"</table>";
                
                
            }
            else
                echo 
"El carro está vacío";
    
            
//Campos que nos serviran para informar la cesta de lo que llevamos comprados y que se mostrará en 
            //la página PRODUCTOS.
            
$_SESSION["totalcoste"] = $totalcoste;
            
$_SESSION["cantidadTotal"] = $xTotal;
            echo (
"<a href='javascript:history.back(1)'>Regresar</a>")
        
        
?>
Esto es en la página http://www.dejavu.com.mx/carro.php

Nuevamente agradezco las molestias que te has tomado.
Saludos

Mi problema ahora es que en carro.php no me toma el producto ni el precio, solo la parte del color y la cantidad y por lo mismo no me hace la suma, siempre se queda en $0