Foros del Web » Programando para Internet » PHP »

Calcular cantidad y total Carro Compra

Estas en el tema de Calcular cantidad y total Carro Compra en el foro de PHP en Foros del Web. holas a todos soy nuevo en este foro y en php la cosa es q toy asiendo un carro de compras para mi pagina donde ...
  #1 (permalink)  
Antiguo 01/12/2009, 23:11
 
Fecha de Ingreso: diciembre-2009
Mensajes: 39
Antigüedad: 14 años, 5 meses
Puntos: 0
Pregunta Calcular cantidad y total Carro Compra

holas a todos soy nuevo en este foro y en php

la cosa es q toy asiendo un carro de compras para mi pagina donde se me guarda los productos en la tabla carrito y los obtengo mediante el MM_Username

weno la cosa es que me agrega y me elimina los productos de manera correcta

como pueden ver enta imagen




pero el problema radica es que nose como sacar el subtotal de los precios ni tampoco calcular con respecto ala cantidad

lo que quiero es al poner en cantidad "2" y dps al actualizar la pagina que grabado el numero 2 pero no lo consigo =/ menos sacar el total

aver si alguien de aca me echa una manoo

saludos!
*
  #2 (permalink)  
Antiguo 02/12/2009, 03:39
 
Fecha de Ingreso: marzo-2007
Mensajes: 89
Antigüedad: 17 años, 1 mes
Puntos: 0
Respuesta: Calcular cantidad y total Carro Compra

Tienes reconocidas las variables donde se almacena el coste de cada producto?
  #3 (permalink)  
Antiguo 02/12/2009, 08:00
 
Fecha de Ingreso: julio-2003
Ubicación: Cochabamba Bolivia
Mensajes: 300
Antigüedad: 20 años, 9 meses
Puntos: 14
Respuesta: Calcular cantidad y total Carro Compra

Hola, solo asi no te pondemos ayudar mucho, seria bueno que pongas tu codigo y la estructura de tu base de datos o de tu tabla y sus campos.

Saludos.
__________________
:policia: Uno para todos y todos para uno.
  #4 (permalink)  
Antiguo 02/12/2009, 09:07
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: Calcular cantidad y total Carro Compra

Deberias usar un input hidden y poner en el el precio de cada producto, luego al hacer click en actualizar, levantar ambas variables (precio y cantidad), multiplicarlas e imprimirlas en pantalla
  #5 (permalink)  
Antiguo 03/12/2009, 18:13
 
Fecha de Ingreso: diciembre-2009
Mensajes: 39
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Calcular cantidad y total Carro Compra

este es el codigo que tengo

Código PHP:
<?php require_once('Connections/tesis.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  
session_start();
}

// ** Logout the current user. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  
//to fully log out a visitor we need to clear the session varialbles
  
$_SESSION['MM_Username'] = NULL;
  
$_SESSION['MM_UserGroup'] = NULL;
  
$_SESSION['PrevUrl'] = NULL;
  unset(
$_SESSION['MM_Username']);
  unset(
$_SESSION['MM_UserGroup']);
  unset(
$_SESSION['PrevUrl']);
    
  
$logoutGoTo "default.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$colname_Recordset1 "-1";
if (isset(
$_POST['MM_Username'])) {
  
$colname_Recordset1 $_POST['MM_Username'];
}
mysql_select_db($database_tesis$tesis);
$query_Recordset1 sprintf("SELECT * FROM usuario WHERE usuEmail = %s"GetSQLValueString($totalRows_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$tesis) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);

$colname_carrito "%";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_carrito $_SESSION['MM_Username'];
}
mysql_select_db($database_tesis$tesis);
$query_carrito sprintf("SELECT empresas.empNombre, productos.proNombre, carrito.carCantidad, carrito.carFecha, carrito.proPrecio, carrito.carCodigo, carrito.usuEmail FROM carrito Inner Join empresas ON empresas.empRut = carrito.empRut Inner Join productos ON productos.proCodigo = carrito.proCodigo WHERE carrito.usuEmail = %s ORDER BY carCodigo ASC"GetSQLValueString($colname_carrito"text"));
$carrito mysql_query($query_carrito$tesis) or die(mysql_error());
$row_carrito mysql_fetch_assoc($carrito);
$totalRows_carrito mysql_num_rows($carrito);
?>
<!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ítulo</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>&nbsp;</p>
  <table width="40%" height="79" border="1">
    <tr>
      <th width="12%" scope="col">Fecha</th>
      <th width="7%" scope="col">Empresa</th>
      <th width="7%" scope="col">Producto</th>
      <th width="12%" scope="col">Cantidad</th>
      <th width="12%" scope="col">Total</th>
      <th width="50%" scope="col">Acciones</th>
    </tr>
    <?php do { ?>
      <tr>
        <th height="20" scope="row"><?php echo $row_carrito['carFecha']; ?>&nbsp;<strong></strong></th>
        <td align="center" valign="middle"><?php echo $row_carrito['empNombre']; ?></td>
        <td><?php echo $row_carrito['proPrecio']; ?></td>
        <td align="center"><input name="carCantidad[]" type="text" id="carCantidad[]" value="<?php echo $row_carrito['carCantidad']; ?>" size="2  value=" <?php if (!(strcmp($row_carrito['carCantidad'],0))) {echo "texted=\"texted\"";} ?><?php echo $row_carrito['carCantidad']?>"/></td>
        <td align="center"><?php echo $row_carrito['proPrecio']; ?></td>
        <td align="center"><strong><a href="del_carro.php?carCodigo=<?php echo $row_carrito['carCodigo']; ?>"><img src="templates/1/sources/html/images/trash.gif" alt="d" width="12" height="14" /></a></strong></td>
      </tr>
      <?php } while ($row_carrito mysql_fetch_assoc($carrito)); ?>
<tr>
      <th height="22" colspan="6" scope="row">SUBTOTAL =
      <?php $carrito=mysql_query("select proPrecio from carrito");
while (
$row_carrito mysql_fetch_assoc($carrito))
$total$row_carrito['proPrecio'] + $row_carrito['proPrecio'];

echo 
$total //muestra la suma total

?></th>
    </tr>
  </table>
</form>
<a href="<?php echo $logoutAction ?>">Desconectar</a>
</body>
</html>
<?php
mysql_free_result
($carrito);
?>
como pueden ver es un juego de registros simple que me lista los productos de la tabla carrito que se guardan en mi bd...
trate de hacer una suma simple al final pero no me resulto , lo de las cantidad tpco lo entiendo mucho como poder conservarlas asiendo un actualizar
  #6 (permalink)  
Antiguo 03/12/2009, 22:59
 
Fecha de Ingreso: diciembre-2009
Mensajes: 39
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Calcular cantidad y total Carro Compra

bumpppppp up
  #7 (permalink)  
Antiguo 04/12/2009, 03:40
 
Fecha de Ingreso: enero-2009
Mensajes: 434
Antigüedad: 15 años, 3 meses
Puntos: 5
Respuesta: Calcular cantidad y total Carro Compra

Es lo mejor que puedes encontrar

http://www.programacionweb.net/artic...iculo/?num=329
  #8 (permalink)  
Antiguo 04/12/2009, 09:17
 
Fecha de Ingreso: diciembre-2009
Mensajes: 39
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Calcular cantidad y total Carro Compra

Cita:
Iniciado por esunestudio Ver Mensaje
sii ya lo abia visto ese lo probe y funciona pero asu manera....

mi carro esta echo de otra forma y solo nesesito sacar el total del precio de cada producto y multiplicarlo por la cantidada

alguien que me ayude con el codigo porfa
  #9 (permalink)  
Antiguo 04/12/2009, 10:05
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: Calcular cantidad y total Carro Compra

No probastecon lo que te dije antes? pone los datos en un input hidden, y pones otro input para que ingresen la cantidad. Cuando van a la siguiente pagina, levantas todas las variables y las multiplicas y mostras el resultado!
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 16:14.