Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/09/2011, 08:59
kushanku
 
Fecha de Ingreso: noviembre-2008
Mensajes: 28
Antigüedad: 15 años, 5 meses
Puntos: 0
catalogo de productos

Hola a todos y muchas gracias de ante mano, tengo un catalogo de productos que al seleccionar el producto y la cantidad envio por post a agregar.php.

El producto y la cantidad lo recibo correctamente mi problema surge cuando tengo que calcular el total me podrian por favor ayudar a continuacion coloco mi codigo.


listado de productos.php
=======================
<?php
include("conector.php");
$sql = "select * from producto where id_categoria = '".$_GET['id_categoria']."'";
$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>LESICOS</title>
</head>

<body>
<form method="post" action="agregar.php">
<table border="1" align="center" width="310" cellpadding="2" cellspacing="2">
<tr align="center">
<td>Producto</td>
<td>Precio</td>
<td>Cantidad</td>
<td><input type="submit" name="enviar" value="Agregar"></td>
</tr>
<?php
if(mysql_num_rows($result) > 0)
{
//$contador = 0;
while($fila = mysql_fetch_assoc($result))
{
?>
<tr align="center">
<td><?php echo $fila["nom_prod"];?></td>
<td><?php echo $fila["precio"];?></td>
<td>
<select name="cantidad[<?php echo $contador; ?>]">
<option value="0">0</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>
</select>
</td>
<td><?php echo"<input type='checkbox' name='seleccion[$contador]' value='$fila[nom_prod]'/>";?></td>
</tr>
<?php
}//fin del while
}//fin del if
else{
echo "No se encontraron datos para mostrar";
}//fin del else
?>
</table>
</form>
<?php
mysql_free_result($result);
?>
</body>
</html>

agregar.php
====================

<?php
$id_prod =$_POST['id_prod'];
$cantidad=$_POST['cantidad'];
$seleccion=$_POST['seleccion'];
$precio=$_POST['precio'];
if(count($seleccion) > 0){
foreach($seleccion as $contador => $valor)
{

$productos .= "
<table border = '1' align = 'center' width = '300'>
<tr align = 'center'>
<td>Producto</td>
<td>Cantidad</td>
<td>Total a Pagar</td>
</tr>
<tr align = 'center'>
<td>$valor</td>
<td>$cantidad[$contador] <br></td>
<td></td>
</tr>
</table>";
}
}
echo $productos;
?>


Muchas gracias a todos por la ayuda.