Foros del Web » Programando para Internet » PHP »

listado de productos

Estas en el tema de listado de productos en el foro de PHP en Foros del Web. hola a todos espero que me puedan ayudar con un carro de compras. Bueno tengo un listado de productos con categorias, el problema es que ...
  #1 (permalink)  
Antiguo 10/01/2011, 10:39
 
Fecha de Ingreso: noviembre-2008
Mensajes: 28
Antigüedad: 15 años, 5 meses
Puntos: 0
listado de productos

hola a todos espero que me puedan ayudar con un carro de compras.

Bueno tengo un listado de productos con categorias, el problema es que al hacer clic en uno de los productos este no me envia al carro de compras y no me lista el producto que seleccione, no se si lo estoy haciendo mal, pero envia un mensaje en pantalla que dice "Warning: Invalid argument supplied for foreach() in c:\appserv\www\lista_productos\cart\agregar_carrit o.php on line 33"

el codigo lo dejo aca espero que me puedan ayudar y muchas gracias a todos.

listado de productos
el archivo se llama list_prod
=====================
<?php
$sql = sprintf("select * from producto where id_cat ='" . $_GET['id_cat'] . "'");
$result = mysql_query($sql, $conexion) or die (mysql_error());
?>
<!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>Documento sin t&iacute;tulo</title>
</head>
<body>
<table width="741" border="0" align="center" cellspacing="1" cellpadding="0">

<?php
$contador = 0;
while($fila = mysql_fetch_assoc($result))
{
?>
<tr>
<td colspan="3" rowspan="2"><div align="center"><img src="images/<?php echo $fila["images"]?>.jpg"/></div></td>
<td width="84" align="left" valign="top">Marca</td>
<td width="519" align="left" valign="top">: <?php echo $fila["descripcion"];?></td>
</tr>
<tr>
<td width="84" align="left" valign="top">Precio</td>
<td width="519" align="left" valign="top">: <?php echo $fila["precio"];?> $</td>
</tr>
<tr>
<td colspan="3"></td>
<td width="84" align="left" valign="top">Cantidad</td>
<td colspan="3">
: <select name="cantidad[<?php echo $contador ;?>]">
<option></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="hidden" name="id_producto" id="id_producto" value="<?php echo $fila["id_producto"]?>" />
<input type="hidden" name="descripcion" id="descripcion" value="<?php echo $fila["descripcion"]?>" />
<input type="hidden" name="precio" id="precio" value="<?php echo $fila["precio"]?>" />
</td>
</tr>
<tr>
<td colspan="3"><br></td>
</tr>
<tr>
<td colspan="4" class="btn"><div align="center"><a href="agregar_carrito.php?id_producto=<?php echo $fila['id_producto']; ?>"><img src="images/carrito.gif" width="30" height="27" border="0"></a></div></td>
</tr>
<?php
$contador++;
}
?>

</table>
<?php
mysql_free_result($result);
?>
</body>
</html>

agregar_carrito.php
===================

<?php
//inicio la seseion
session_start();

//incluyo la conexion a la base de datos
include_once("conector.php");

//inicializo la session del carro de compras
if(isset($_SESSION['carro']))
{
$carro = $_SESSION['carro'];
}
//realizo la consulta
?>
<html>
<head>
<title>PRODUCTOS AGREGADOS AL CARRITO</title>
</head>
<body>
<p align="center">CARRITO DE COMPRAS </p>
<table width="609" border="1" cellspacing="0" cellpadding="0" align="center">
<tr class="prod">
<td width="45"><span class="Estilo7">Nro</span></td>
<td width="329"><span class="Estilo7">Descripcion</span></td>
<td width="41"><span class="Estilo7">Precio</span></td>
<td width="67" align="center"><span class="Estilo7">Cantidad</span></td>
<td width="59" align="center"><span class="Estilo7">Importe</span></td>
<td width="54" align="center"><span class="Estilo7">Borrar</span></td>
</tr>
<?php
$contador=0;
$st=0;
foreach($carro as $k => $v){
$importe=$v['cantidad']*$v['precio'];
$st=$st+$importe;
$contador++;
?>
<tr>
<td><div align="center"><?php echo $contador; ?></div></td>
<td><?php echo $v['descripcion'] ?></td>
<td><?php echo $v['precio'] ?></td>
<td><?php echo $v['cantidad'] ?> </td>
<td><strong><?php echo $importe; ?></strong> </td>
<td width="54" align="center"> <a href="borrar.php?id_producto=<?php echo $v['codigo'] ?>">quitar</a></td>
</tr>
<?php } ?>
</table>
<table width="614" border="0" cellspacing="0" cellpadding="0" align="center">
<tr class="prod">
<td width="53">&nbsp;</td>
<td width="340">&nbsp;</td>
<td width="55">&nbsp;</td>
<td width="85" align="center"><div align="left">Sub Total </div></td>
<td width="43" align="center"><div align="left"><strong><?php echo $st; ?></strong></div></td>
<td width="38" align="center">&nbsp;</td>
</tr>
<tr class="prod">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="center"><div align="left">IGV</div></td>
<td align="center"><div align="left"><strong><?php echo $st*0.19; ?></strong></div></td>
<td align="center">&nbsp;</td>
</tr>
<tr class="prod">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="center"><div align="left">Total Pago </div></td>
<td align="center"><div align="left"><strong><?php echo $st+($st*0.19); ?></strong></div></td>
<td align="center">&nbsp;</td>
</tr>
<tr class="prod">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="center"><div align="left"></div></td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr class="prod">
<td colspan="6">[<a href="principal.php">Continuar comprando</a>] [<a href="javascript:;">Vaciar carrito de compras</a>] [<a href="javascript:;"><strong>Cerrar Session</strong></a>] [<a href="ordenar_compra.php">Finalizar Compra</a>]
<div align="left"></div></td>
</tr>
<?php
$contador=0;
$suma=0;
foreach($carro as $k => $v){
$importe=$v['cantidad']*$v['precio'];
$suma=$suma+$subto;
$contador++;
?>
<?php
}
?>
</table>
<p>&nbsp;</p>
</body>
</html>

y el archivo que agrega el producto al carro
=================================

<?php
session_start();
$id_producto=$_POST['id_producto'];
$carro[$id_producto] = array(
"id_producto" => $_POST['id_producto'],
"descripcion" => $_POST['descripcion'],
"cantidad" => $_POST['cantidad'],
"precio" => $_POST['precio'],
);
$_SESSION['carro']=$carro;
header("Location:agregar_carrito.php");
?>

Etiquetas: listado, productos
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 06:37.