Ver Mensaje Individual
  #9 (permalink)  
Antiguo 16/11/2007, 14:33
Avatar de franhanck
franhanck
 
Fecha de Ingreso: enero-2005
Mensajes: 115
Antigüedad: 19 años, 3 meses
Puntos: 0
Pregunta Re: Problema con los Array

ohhh no otro problema tengo este codigo
Código PHP:
<?php // Manual de PHP de WebEstilo.com
session_start();
$_SESSION['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;
?>
<html>
<body>
<tt>
<form action="<?=$PHP_SELF."?".$SID?>" method="post">
Dime el producto <input type="text" name="item" size="20"><br>
Cuantas unidades <input type="text" name="cantidad" size="20"><br>
<input type="submit" value="Añadir a la cesta"><br>
</form>
<?
if (isset($itemsEnCesta)){
   echo
'El contenido de la cesta de la compra es:<br>';
   foreach(
$itemsEnCesta as $k => $v){
      echo 
'Artículo: '.$k.' ud: '.$v.'<br>';
   }
}
?>
</tt>
</body>
</html>
el cual funciona super bien y lo he estado modificando y llegue a esto;
Código PHP:
<?
$_SESSION
["material"];
$codigo=$_GET["cod"];
$cantidad=$_GET["cantidad"];
$precio=$_GET["precio"];
$detalle=$_GET["detalle"];
$total=$_GET["total"];
$material=$_SESSION["material"];

//$material=array ($codigo=>array( $cantidad,$detalle,$precio,$total));
$_SESSION["material"]=$material;
if (
$codigo){
   if (!isset(
$material)){
      
$material=array ($codigo=>array( $cantidad,$detalle,$precio,$total));
   }else{
      foreach(
$material as $k => $v){
         if (
$codigo==$k){
          
$material=array ($k=>array( $cantidad,$detalle,$precio,$total));
         
$encontrado=1;
         }
      }
      if (!
$encontrado)$material=array ($codigo=>array( $cantidad,$detalle,$precio,$total));
   }
}
$_SESSION['material']=$material;
?> 

<form id="form1" name="form1" method="get" action="<? $PHP_SELF ?>">

    <p>&nbsp;</p>
    <table width="200" border="1">
      <tr>
        <td>Codigo</td>
        <td>Cantidad</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><input type="text" name="cod" /></td>
        <td><input name="detalle" type="text" id="detalle" /></td>
        <td><input type="text" name="cantidad" /></td>
        <td><input type="text" name="precio" /></td>
        <td><input name="total" type="text" id="total" /></td>
        <td><input type="submit" name="Submit" value="Enviar" /></td>
      </tr>
    </table>
   </form>
   <?

if (isset($material)){  
foreach(
$material as $key=>$value)
{
  echo 
$key." ";
 foreach (
$value as $key1=>$value1)
   echo 
$value1." ";
 echo 
"<br>";
}
}
   
?>
quiero hacer casi lo mismo pero no entiendo cual es mi error los datos se me ven pero no como en el primer ejemplo

porfa si alguien puede ayudarme y probar los codigos y decirme que estoy haciedo mal solo quise agregar mas campos y parese que no me resulto
__________________
Si fuera eterno sabría todo pero como no lo soy recurro al foro al cabo que siempre hay alguien que sepa más que uno Gracias amigos son de mucha ayuda