Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/02/2011, 09:58
Avatar de TylerD
TylerD
 
Fecha de Ingreso: enero-2011
Mensajes: 22
Antigüedad: 13 años, 3 meses
Puntos: 1
Respuesta: Problema con array

Muestro los 2 codigos que estara el problema:

este es el php donde muestro los productos del carrito:

Código PHP:
 <?php
  $color
=array("#ffffff","#F0F0F0");
  
$contador=0;
  
$suma=0;
  
$prod=0;
  
$_SESSION['prods']=$prod;
  
   foreach(
$carro as $k => $v){
   
$subto=$v['cantidad']*$v['precio'];
   
$suma=$suma+$subto;
   
$prod=$prod+$v['cantidad'];
   
$contador++;
   
    
?>
  <form name="a<?php echo $v['identificador'?>" method="post" action="agregacar.php?<?php echo SID ?>" id="a<?php echo $v['identificador'?>">
    <tr bgcolor="<?php echo $color[$contador%2]; ?>" class='prod'> 
      <td><?php echo $v['nom_prod'?></td>
      <td bgcolor="<?php echo $color[$contador%2]; ?>"><?php echo $v['precio'?></td>
      <td width="90" align="center"><?php echo $v['cantidad'?></td>
      <td width="150" align="center"> 
        <input name="cantidad" type="text" id="cantidad" value="<?php echo $v['cantidad'?>" size="4">
      <input name="cod_prod" type="hidden" id="cod_prod" value="<?php echo $v['cod_prod'?>"> </td>
      <td align="center"><a href="borracar.php?<?php echo SID ?>&cod_prod=<?php echo $v['cod_prod'?>"><img src="trash.gif" width="12" height="14" border="0"></a></td>
      <td align="center">
        <input name="imageField" type="image" src="actualizar.gif" width="20" height="20" border="0"></td>
  </tr></form>
  <?php }?>
y este es el archivo que agrega los productos :

Código PHP:
<?php 
session_start
();

extract($_REQUEST);
 
mysql_connect("localhost","root","xxx");
mysql_select_db("proyecto");

if(!isset(
$cantidad)){$cantidad=1;}

$qry=mysql_query("select * from productos where cod_prod='".$cod_prod."'");
$row=mysql_fetch_array($qry);

if(isset(
$carro)){
 foreach(
$carro as $k => $v){
   if (
$cod_prod == $v['cod_prod'])
   {
$cantidad $v['cantidad'] + 1;}
}}
$_SESSION['carro']

if(isset(
$_SESSION['carro']))
$carro=$_SESSION['carro'];

$carro[md5($cod_prod)]=array('identificador'=>md5($cod_prod),'cantidad'=>$cantidad,'nom_prod'=>$row['nom_prod'],'precio'=>$row['precio'],'cod_prod'=>$cod_prod);

$_SESSION['carro']=$carro;

header("Location:indexcarrito.php?".SID);
?>