Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/03/2012, 09:37
Avatar de informacionsys
informacionsys
 
Fecha de Ingreso: mayo-2011
Ubicación: Bogota D.C
Mensajes: 793
Antigüedad: 13 años
Puntos: 76
Respuesta: Sumar valores de un registro

hola ....

puedes hacerlo asi :

Código PHP:
Ver original
  1. $q_consulta = "SELECT SUM(campo) as total FROM table";
  2. $resultSet = mysql_query($q_consulta);
  3. $regSet = mysql_fetch_object($resultSet);
  4. echo $regSet->total;

o

Código PHP:
Ver original
  1. $q_consulta = "SELECT  *  FROM table";
  2. $resultSet = mysql_query($q_consulta);
  3. $suma = 0;
  4. while  ($regSet = mysql_fetch_object($resultSet)){
  5.          $valor = $regSet->campo;
  6.          $suma += $valor;
  7. }
  8. echo "valor total".$suma;