Foros del Web » Programando para Internet » PHP »

Ayuda con Codigo Extraño

Estas en el tema de Ayuda con Codigo Extraño en el foro de PHP en Foros del Web. Código: <?php // Manual de PHP session_start(); session_register('itemsEnCesta'); $item=$_POST['item']; $cantidad=$_POST['cantidad']; $itemsEnCesta=$_SESSION['itemsEnCesta']; if ($item){ if (!isset($itemsEnCesta)){ $itemsEnCesta[$item]=$cantidad; }else{ foreach($itemsEnCesta as $k => $v){ if ($item==$k){ $itemsEnCesta[$k]+=$cantidad; ...
  #1 (permalink)  
Antiguo 10/06/2008, 11:43
Avatar de xxrandyxx  
Fecha de Ingreso: abril-2008
Ubicación: En mi casa
Mensajes: 143
Antigüedad: 16 años
Puntos: 2
Ayuda con Codigo Extraño

Código:
<?php // Manual de PHP  
session_start();  
session_register('itemsEnCesta');  
$item=$_POST['item'];  
$cantidad=$_POST['cantidad'];  
$itemsEnCesta=$_SESSION['itemsEnCesta'];  
if ($item){  
   if (!isset($itemsEnCesta)){  
      $itemsEnCesta[$item]=$cantidad;  
   }else{  
      foreach($itemsEnCesta as $k => $v){  
         if ($item==$k){  
         $itemsEnCesta[$k]+=$cantidad;  
         $encontrado=1;  
         }  
      }  
      if (!$encontrado) $itemsEnCesta[$item]=$cantidad;  
   }  
}  
$_SESSION['itemsEnCesta']=$itemsEnCesta; 
?>
Buenas tengo este codigo y quiero agregar un valor mas, tengo item y tengo cantidad, quisiera agregar precio y otras cosas mas, la verdad me he confundido, porfavor arreglene este codigo o diganme como le agrego una mas PLEASE!!!
  #2 (permalink)  
Antiguo 10/06/2008, 11:48
 
Fecha de Ingreso: enero-2008
Mensajes: 163
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

bueno me imagino que ese codigo es de un carrito si quieres agregar precio seria
Código PHP:
<?php // Manual de PHP  
session_start();  
session_register('itemsEnCesta');  
$item=$_POST['item'];  
$cantidad=$_POST['cantidad'];  
$itemsEnCesta=$_SESSION['itemsEnCesta'];
$precio=$_POST['precio']; /* AQUI PONDRIAS PRECIO Y OTRAS VARIABLES claro esta esto es nadamas
el codigo, EL html que te envia a esa parte del codigo tienes que crear un textfield con el nombre de
precio si no no funcionara te recomiendo leer mas de php */

//TODO LO que sigue es nomas para definir items encesta
if ($item){  
   if (!isset(
$itemsEnCesta)){  
      
$itemsEnCesta[$item]=$cantidad;  
   }else{  
      foreach(
$itemsEnCesta as $k => $v){  
         if (
$item==$k){  
         
$itemsEnCesta[$k]+=$cantidad;  
         
$encontrado=1;  
         }  
      }  
      if (!
$encontrado$itemsEnCesta[$item]=$cantidad;  
   }  
}  
$_SESSION['itemsEnCesta']=$itemsEnCesta
?>
  #3 (permalink)  
Antiguo 10/06/2008, 11:54
Avatar de xxrandyxx  
Fecha de Ingreso: abril-2008
Ubicación: En mi casa
Mensajes: 143
Antigüedad: 16 años
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

Gracias por responder, pero mira el codigo de mi form en php!

[CODE]<?
if (isset($itemsEnCesta)){
foreach($itemsEnCesta as $k => $v){
echo '<table width="300" border="0" align="center" cellpadding="0" cellspacing="0" class="texto_gris">
<tr>
<td width="100" align="center">'.$k.'</td>
<td width="100" align="center">'.$p.'</td>
<td width="100" align="center">'.$v.'</td>
</tr>
</table>';
}

}

else{
echo 'Usted no ha agregado nada al carrito de compras';}
?>[CODE]


Si te dascuenta toma los valores de k y v ke son item y contendio pero como le doy el valor P de precio, ya que no se como hace pero se crea un valor con v y k en el otro ke te mande, Como hago para agregarle ese valor .$p.


foreach($itemsEnCesta as $k => $v){ ?=???
  #4 (permalink)  
Antiguo 10/06/2008, 12:05
 
Fecha de Ingreso: enero-2008
Mensajes: 163
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

a caray aver empesando por lo primero de donde verijas sale el valor de $v y que significa ya que no se = con otra variable $k es la cantidad de items en la cesta pero $v donde agarra el valor o que transa
  #5 (permalink)  
Antiguo 10/06/2008, 12:06
Avatar de xxrandyxx  
Fecha de Ingreso: abril-2008
Ubicación: En mi casa
Mensajes: 143
Antigüedad: 16 años
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

la verdad ni yo se, pero me vota el valor correctamente !!!
  #6 (permalink)  
Antiguo 10/06/2008, 12:08
 
Fecha de Ingreso: enero-2008
Mensajes: 163
Antigüedad: 16 años, 3 meses
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

pero el valor de que es el que imprime
  #7 (permalink)  
Antiguo 10/06/2008, 12:09
Avatar de xxrandyxx  
Fecha de Ingreso: abril-2008
Ubicación: En mi casa
Mensajes: 143
Antigüedad: 16 años
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

Te dejo mis codigos


Este es de mi seccion de productos


Código:
<?php // [email protected]
session_start();  
session_register('itemsEnCesta');  
$item=$_POST['item'];  
$cantidad=$_POST['cantidad'];  
$itemsEnCesta=$_SESSION['itemsEnCesta'];  
if ($item){  
   if (!isset($itemsEnCesta)){  
      $itemsEnCesta[$item]=$cantidad;  
   }else{  
      foreach($itemsEnCesta as $k => $v)
	        foreach($itemsEnCesta as $k => $v){  
         if ($item==$k){  
         $itemsEnCesta[$k]+=$cantidad;  
         $encontrado=1;  
         }  
      }  
      if (!$encontrado) $itemsEnCesta[$item]=$cantidad;  
   }  
}  
$_SESSION['itemsEnCesta']=$itemsEnCesta; 
?>

Siguiendo esto mas abajo, claro toy dando sin html

Código:
<form action="<?=$PHP_SELF."?".$SID?>" method="post">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td align="center"><span class="text4sinspace">Codigo del Producto</span></td>
                    </tr>
                    <tr>
                      <td align="center"><span class="text4sinspace">
                        <input name="item" type="text" class="texto_red_black" id="item" value="<?php echo $row_rs_detalles_stock['item']; ?>" size="5" maxlength="10">
                      </span></td>
                    </tr>
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                    <tr>
                      <td align="center"><span class="text4sinspace">Cuantas unidades </span></td>
                    </tr>
                    <tr>
                      <td align="center"><span class="text4sinspace">
                        <input name="cantidad" type="text" class="text4sinspace2" id="cantidad" value="1" size="5" maxlength="10">
                      </span></td>
                    </tr>
                    <tr>
                      <td align="center">&nbsp;</td>
                    </tr>
                  </table>
                  <span class="text4sinspace">
                  <input type="submit" class="text4" value="Agregar ">
                  </span><br>
              </form>

Y este es de mi carrito


Código:
<?php // Manual de PHP  
session_start();  
session_register('itemsEnCesta');  
$item=$_POST['item'];  
$cantidad=$_POST['cantidad'];  
$itemsEnCesta=$_SESSION['itemsEnCesta'];  
if ($item){  
   if (!isset($itemsEnCesta)){  
      $itemsEnCesta[$item]=$cantidad;  
   }else{  
      foreach($itemsEnCesta as $k => $v){  
         if ($item==$k){  
         $itemsEnCesta[$k]+=$cantidad;  
         $encontrado=1;  
         }  
      }  
      if (!$encontrado) $itemsEnCesta[$item]=$cantidad;  
   }  
}  
$_SESSION['itemsEnCesta']=$itemsEnCesta; 
?>  



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>INTERWATT // EL BENEFICIO DE LO DURABLE</title>
<link href="estilos/stilos.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
.catalogo {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #333333;
}
-->
</style>
</head>

<body onload="scroll()">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="top"><table width="536" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="10">&nbsp;</td>
        <td height="200" align="center" background="imagenes/degra.jpg" class="texto_gigante">LA TIENDA VIRTUAL DEL CALOR</td>
      </tr>
      <tr>
        <td height="20">&nbsp;</td>
        <td height="20" align="left"><span class="texto_black"><img src="http://www.theivyat78704.com/images/asterisk_orange.png" alt="" /> CARRITO DE COMPRAS</span></td>
      </tr>
      <tr>
        <td height="1"></td>
        <td height="1" align="left" bgcolor="#666666"></td>
      </tr>
      <tr>
        <td height="300"></td>
        <td height="300" align="center" valign="top"><tt class="text4sinspace"><br />
          <br />
          </tt>
          
          <tt class="text4sinspace"><table width="300" border="0" align="center" cellpadding="0" cellspacing="0" class="texto_gris">
            <tr>
              <td width="100" align="center" bgcolor="#CCCCCC">Codigo</td>
              <td width="100" align="center" bgcolor="#CCCCCC">Precio</td>
              <td width="100" align="center" bgcolor="#CCCCCC">Unidades</td>
              </tr>
          </table><?  
if (isset($itemsEnCesta)){  
   foreach($itemsEnCesta as $k => $v){
      echo '<table width="300" border="0" align="center" cellpadding="0" cellspacing="0" class="texto_gris">
            <tr>
              <td width="100" align="center">'.$k.'</td>
              <td width="100" align="center">'.$p.'</td>
              <td width="100" align="center">'.$v.'</td>
            </tr>
          </table>'; 
   }  

}  

else{
   echo 'Usted no ha agregado nada al carrito de compras';}
?>
                  </tt></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

HELP!
  #8 (permalink)  
Antiguo 10/06/2008, 12:11
Avatar de xxrandyxx  
Fecha de Ingreso: abril-2008
Ubicación: En mi casa
Mensajes: 143
Antigüedad: 16 años
Puntos: 2
Respuesta: Ayuda con Codigo Extraño

Si quieren pruebenlo, funciona!

Por eso no entiendo como saca el valor y los saca bien!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:46.