Autor Tema: PHP y MySql obtener el sumatorio de una columna con SELECT SUM FROM PHPMyAdmin  (Leído 13368 veces)

FGP

  • Sin experiencia
  • *
  • Mensajes: 10
    • Ver Perfil
    • Undergroove Beats Records
Hola quisiera solicitar de su apoyo, estoy mostrando de mi DB, una tabla en la cual logre sumar y calcular el promedio (con un juego de registros en dreamweaver),

Sin embargo ahora no logro sumar las filas por lo que requiero de su apoyo.
Les envío el código para ver si me pueden apoyar:


Código: [Seleccionar]
<?php require_once('../Connections/local.php'); ?>
<?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;
}
}


$currentPage $_SERVER["PHP_SELF"];


$maxRows_cant_cursos_andes 10;
$pageNum_cant_cursos_andes 0;
if (isset(
$_GET['pageNum_cant_cursos_andes'])) {
  
$pageNum_cant_cursos_andes $_GET['pageNum_cant_cursos_andes'];
}
$startRow_cant_cursos_andes $pageNum_cant_cursos_andes $maxRows_cant_cursos_andes;


mysql_select_db($database_local$local);
$query_cant_cursos_andes "SELECT * FROM `cantidad de cursos region andes`";
$query_limit_cant_cursos_andes sprintf("%s LIMIT %d, %d"$query_cant_cursos_andes$startRow_cant_cursos_andes$maxRows_cant_cursos_andes);
$cant_cursos_andes mysql_query($query_limit_cant_cursos_andes$local) or die(mysql_error());
$row_cant_cursos_andes mysql_fetch_assoc($cant_cursos_andes);


if (isset(
$_GET['totalRows_cant_cursos_andes'])) {
  
$totalRows_cant_cursos_andes $_GET['totalRows_cant_cursos_andes'];
} else {
  
$all_cant_cursos_andes mysql_query($query_cant_cursos_andes);
  
$totalRows_cant_cursos_andes mysql_num_rows($all_cant_cursos_andes);
}
$totalPages_cant_cursos_andes ceil($totalRows_cant_cursos_andes/$maxRows_cant_cursos_andes)-1;


$queryString_cant_cursos_andes "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_cant_cursos_andes") == false && 
        
stristr($param"totalRows_cant_cursos_andes") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_cant_cursos_andes "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_cant_cursos_andes sprintf("&totalRows_cant_cursos_andes=%d%s"$totalRows_cant_cursos_andes$queryString_cant_cursos_andes);


$totales $row_cant_cursos_andes;


session_start();
require(
"conexion.php");
$usu=$_SESSION['usuario'];
$consulta11=mysql_query("SELECT * FROM usuario where usuario='$usu' ") or die(mysql_error());
$pacientes=mysql_fetch_array($consulta11);
$usu=$pacientes['nombre']." ".$pacientes['apellido'];
?>




<!doctype html>
<html>
<head>

</head>


<body>



<table border="1" align="center" bgcolor="#CBCBCB" width="1280">
  <tr bgcolor="#DBDBDB">
    <td><strong>Región</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Enero</strong></td>
    <td><strong>Febrero</strong></td>
    <td><strong>Marzo</strong></td>
    <td><strong>Abril</strong></td>
    <td><strong>Mayo</strong></td>
    <td><strong>Junio</strong></td>
    <td><strong>Julio</strong></td>
    <td><strong>Agosto</strong></td>
    <td><strong>Septiembre</strong></td>
    <td><strong>Octubre</strong></td>
    <td><strong>Noviembre</strong></td>
    <td><strong>Diciembre</strong></td>
    <td><strong>Total</strong></td>
    <td><strong>Promedio</strong></td>
    <td><strong>Actualizar</strong></td>
  </tr>
 


  <?php do { ?>
<tr>
      <td bgcolor="#E0E0E0"><strong><?php echo $row_cant_cursos_andes['Region']; ?>&nbsp; </a></strong></td>
      <td><?php echo $row_cant_cursos_andes['year']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Enero']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Febrero']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Marzo']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Abril']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Mayo']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Junio']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Julio']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Agosto']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Septiembre']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Octubre']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Noviembre']; ?>&nbsp; </td>
      <td><?php echo $row_cant_cursos_andes['Diciembre']; ?>&nbsp; </td>
      <td><strong> <?php echo $suma=$row_cant_cursos_andes['Enero']+ $row_cant_cursos_andes['Febrero']+ $row_cant_cursos_andes['Marzo']+ $row_cant_cursos_andes['Abril']+ $row_cant_cursos_andes['Mayo']+ $row_cant_cursos_andes['Junio']+ $row_cant_cursos_andes['Julio']+ $row_cant_cursos_andes['Agosto']+ $row_cant_cursos_andes['Septiembre']+ $row_cant_cursos_andes['Octubre']+ $row_cant_cursos_andes['Noviembre']+ $row_cant_cursos_andes['Diciembre'?>&nbsp; </strong></td>
      <td><strong> <?php $prom=($row_cant_cursos_andes['Enero']+ $row_cant_cursos_andes['Febrero']+ $row_cant_cursos_andes['Marzo']+ $row_cant_cursos_andes['Abril']+ $row_cant_cursos_andes['Mayo']+ $row_cant_cursos_andes['Junio']+ $row_cant_cursos_andes['Julio']+ $row_cant_cursos_andes['Agosto']+ $row_cant_cursos_andes['Septiembre']+ $row_cant_cursos_andes['Octubre']+ $row_cant_cursos_andes['Noviembre']+ $row_cant_cursos_andes['Diciembre'])/12; echo $promround($prom1?>&nbsp; </strong></td>
   
<td><strong><form action="act_cant_cursos/act_cursos_andes.php?year=<?php echo $row_cant_cursos_andes['year']; ?>" method="post">
      <input type="submit" value="Actualizar" style="background-color:#8FB9DA"/> </form></strong>
</td>
       
</tr>   
   
     
<?php } while ($row_cant_cursos_andes mysql_fetch_assoc($cant_cursos_andes)); ?>


</table>


<!-- ------------------------------- Aqui quisiera realizar la suma----------------------------------------- -->


<?php do { ?>


<?php $totales["year"]+=$row_cant_cursos_andes['year']; ?>
<?php $totales["Enero"]+=$row_cant_cursos_andes['Enero']; ?>
<?php $totales["Febrero"]+=$row_cant_cursos_andes['Febrero']; ?>
<?php $totales["Marzo"]+=$row_cant_cursos_andes['Marzo']; ?>
<?php $totales["Abril"]+=$row_cant_cursos_andes['Abril']; ?>
<?php $totales["Mayo"]+=$row_cant_cursos_andes['Mayo']; ?>
<?php $totales["Junio"]+=$row_cant_cursos_andes['Junio']; ?>
<?php $totales["Julio"]+=$row_cant_cursos_andes['Julio']; ?>
<?php $totales["Agosto"]+=$row_cant_cursos_andes['Agosto']; ?>
<?php $totales["Septiembre"]+=$row_cant_cursos_andes['Septiembre']; ?>
<?php $totales["Octubre"]+=$row_cant_cursos_andes['Octubre']; ?>
<?php $totales["Noviembre"]+=$row_cant_cursos_andes['Noviembre']; ?>
<?php $totales["Diciembre"]+=$row_cant_cursos_andes['Diciembre']; ?>


 
<table border="1" align="center" bgcolor="#CBCBCB" width="1280">
</tr>
<td><strong>Total</strong></td>
<td><?php echo $totales["year"]; ?></td>
<td><?php echo $totales["Enero"]; ?></td>
<td><?php echo $totales["Febrero"]; ?></td>
<td><?php echo $totales["Marzo"]; ?></td>
<td><?php echo $totales["Abril"]; ?></td>
<td><?php echo $totales["Mayo"]; ?></td>
<td><?php echo $totales["Junio"]; ?></td>
<td><?php echo $totales["Julio"]; ?></td>
<td><?php echo $totales["Agosto"]; ?></td>
<td><?php echo $totales["Septiembre"]; ?></td>
<td><?php echo $totales["Octubre"]; ?></td>
<td><?php echo $totales["Noviembre"]; ?></td>
<td><?php echo $totales["Diciembre"]; ?></td>
                <td>Total</td>
<td>Promedio</td>
<td>Actualizar</td>
</tr>
</table> 
     <?php } while ($totales $row_cant_cursos_andes); ?>
<!-- -------------------------------Termina Suma de Filas----------------------------------------- -->


<p align="center">Gerencia de Capacitación ®</p>


</body>
</html>


<?php mysql_free_result($cant_cursos_andes);?> 


« Última modificación: 19 de Septiembre 2015, 17:43 por Ogramar »

Ogramar

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2660
    • Ver Perfil
Re:Suma de Filas en PHP con Metodo Do While y DB PHPMyAdmin
« Respuesta #1 en: 16 de Septiembre 2015, 13:23 »
Hola Robinson la suma de filas y el cálculo del promedio la tienes realizada en este fragmento de código:

Código: [Seleccionar]
<td><strong> <?php echo $suma=$row_cant_cursos_andes['Enero']+ $row_cant_cursos_andes['Febrero']+ $row_cant_cursos_andes['Marzo']+ $row_cant_cursos_andes['Abril']+ $row_cant_cursos_andes['Mayo']+ $row_cant_cursos_andes['Junio']+ $row_cant_cursos_andes['Julio']+ $row_cant_cursos_andes['Agosto']+ $row_cant_cursos_andes['Septiembre']+ $row_cant_cursos_andes['Octubre']+ $row_cant_cursos_andes['Noviembre']+ $row_cant_cursos_andes['Diciembre'?>&nbsp; </strong></td>
      <td><strong> <?php $prom=($row_cant_cursos_andes['Enero']+ $row_cant_cursos_andes['Febrero']+ $row_cant_cursos_andes['Marzo']+ $row_cant_cursos_andes['Abril']+ $row_cant_cursos_andes['Mayo']+ $row_cant_cursos_andes['Junio']+ $row_cant_cursos_andes['Julio']+ $row_cant_cursos_andes['Agosto']+ $row_cant_cursos_andes['Septiembre']+ $row_cant_cursos_andes['Octubre']+ $row_cant_cursos_andes['Noviembre']+ $row_cant_cursos_andes['Diciembre'])/12; echo $promround($prom1?>&nbsp; </strong></td>


¿A qué te refieres con que no logras sumar las filas?

Salu2

FGP

  • Sin experiencia
  • *
  • Mensajes: 10
    • Ver Perfil
    • Undergroove Beats Records
Re:Suma de Filas en PHP con Metodo Do While y DB PHPMyAdmin
« Respuesta #2 en: 17 de Septiembre 2015, 05:42 »
Hola amigos, mil disculpas creo que realice mal la consulta.
Efectivamente la suma y el promedio están realizados. Lo que quisiera es sumar los meses, es decir: Enero 2012 + Enero 2013 + Enero 2014 + Enero 2015, así como los meses restantes.

Como pueden observar en la imagen, en la fila "Totales x Mes" me esta mostrando la suma totales mes ames, pero todo lo que coloco en el 2012 me lo esta duplicando.

Creo que se debe a que pasa por el Bucle "Do" pues no consigo resolverlo, ya que si observan aquellos registros que no contenga nada en 2012 lo suma de manera correcta.

Agradecido por lo que me puedan apoyar



Envío la parte del código,



Código: [Seleccionar]

<?php require_once('../Connections/local.php'); ?>
<?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;
}
}

$currentPage $_SERVER["PHP_SELF"];

$maxRows_cant_cursos_andes 10;
$pageNum_cant_cursos_andes 0;
if (isset(
$_GET['pageNum_cant_cursos_andes'])) {
  
$pageNum_cant_cursos_andes $_GET['pageNum_cant_cursos_andes'];
}
$startRow_cant_cursos_andes $pageNum_cant_cursos_andes $maxRows_cant_cursos_andes;

mysql_select_db($database_local$local);
$query_cant_cursos_andes "SELECT * FROM `cantidad de cursos region andes`";
$query_limit_cant_cursos_andes sprintf("%s LIMIT %d, %d"$query_cant_cursos_andes$startRow_cant_cursos_andes$maxRows_cant_cursos_andes);
$cant_cursos_andes mysql_query($query_limit_cant_cursos_andes$local) or die(mysql_error());
$row_cant_cursos_andes mysql_fetch_assoc($cant_cursos_andes);



if (isset(
$_GET['totalRows_cant_cursos_andes'])) {
  
$totalRows_cant_cursos_andes $_GET['totalRows_cant_cursos_andes'];
} else {
  
$all_cant_cursos_andes mysql_query($query_cant_cursos_andes);
  
$totalRows_cant_cursos_andes mysql_num_rows($all_cant_cursos_andes);
}
$totalPages_cant_cursos_andes ceil($totalRows_cant_cursos_andes/$maxRows_cant_cursos_andes)-1;

$queryString_cant_cursos_andes "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_cant_cursos_andes") == false && 
        
stristr($param"totalRows_cant_cursos_andes") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_cant_cursos_andes "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_cant_cursos_andes sprintf("&totalRows_cant_cursos_andes=%d%s"$totalRows_cant_cursos_andes$queryString_cant_cursos_andes);

$totales $row_cant_cursos_andes;

session_start();

// -------------------------------iNICIO DE SESION----------------------------------------- //

require("conexion.php");
$usu=$_SESSION['usuario'];
$consulta11=mysql_query("SELECT * FROM usuario where usuario='$usu' ") or die(mysql_error());
$pacientes=mysql_fetch_array($consulta11);
$usu=$pacientes['nombre']." ".$pacientes['apellido'];
?>


<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
  <tr bgcolor="#E0E0E0">
    <td><strong>Región</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Enero</strong></td>
    <td><strong>Febrero</strong></td>
    <td><strong>Marzo</strong></td>
    <td><strong>Abril</strong></td>
    <td><strong>Mayo</strong></td>
    <td><strong>Junio</strong></td>
    <td><strong>Julio</strong></td>
    <td><strong>Agosto</strong></td>
    <td><strong>Septiembre</strong></td>
    <td><strong>Octubre</strong></td>
    <td><strong>Noviembre</strong></td>
    <td><strong>Diciembre</strong></td>
    <td><strong>Total</strong></td>
    <td><strong>Promedio</strong></td>
    <td><strong>Actualizar</strong></td>
  </tr>
 
 <?php do { ?>
<tr>
<td bgcolor="#E0E0E0"><strong><?php echo $row_cant_cursos_andes['Region']; ?>&nbsp; </a></strong></td>
<td><?php echo $row_cant_cursos_andes['year']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Enero']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Febrero']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Marzo']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Abril']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Mayo']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Junio']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Julio']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Agosto']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Septiembre']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Octubre']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Noviembre']; ?>&nbsp; </td>
<td><?php echo $row_cant_cursos_andes['Diciembre']; ?>&nbsp; </td>
 
<td><strong> <?php echo $suma=$row_cant_cursos_andes['Enero']+ $row_cant_cursos_andes['Febrero']+ $row_cant_cursos_andes['Marzo']+ $row_cant_cursos_andes['Abril']+ $row_cant_cursos_andes['Mayo']+ $row_cant_cursos_andes['Junio']+ $row_cant_cursos_andes['Julio']+ $row_cant_cursos_andes['Agosto']+ $row_cant_cursos_andes['Septiembre']+ $row_cant_cursos_andes['Octubre']+ $row_cant_cursos_andes['Noviembre']+ $row_cant_cursos_andes['Diciembre'?>&nbsp; </strong></td>
 
<td><strong> <?php $prom=($row_cant_cursos_andes['Enero']+ $row_cant_cursos_andes['Febrero']+ $row_cant_cursos_andes['Marzo']+ $row_cant_cursos_andes['Abril']+ $row_cant_cursos_andes['Mayo']+ $row_cant_cursos_andes['Junio']+ $row_cant_cursos_andes['Julio']+ $row_cant_cursos_andes['Agosto']+ $row_cant_cursos_andes['Septiembre']+ $row_cant_cursos_andes['Octubre']+ $row_cant_cursos_andes['Noviembre']+ $row_cant_cursos_andes['Diciembre'])/12; echo $promround($prom1?>&nbsp; </strong></td>
 
<td><strong><form action="act_cant_cursos/act_cursos_andes.php?year=<?php echo $row_cant_cursos_andes['year']; ?>" method="post">
<input type="submit" value="Actualizar" style="background-color:#8FB9DA"/> </form></strong>
</td>
</tr>
   
    <!-- AQUI ES DONDE TENGO EL PROBLEMA -->

    <?php
$totales["year"]+=$row_cant_cursos_andes['year'];
$totales["Enero"]+=$row_cant_cursos_andes['Enero'];
$totales["Febrero"]+=$row_cant_cursos_andes['Febrero'];
$totales["Marzo"]+=$row_cant_cursos_andes['Marzo'];
$totales["Abril"]+=$row_cant_cursos_andes['Abril'];
$totales["Mayo"]+=$row_cant_cursos_andes['Mayo'];
$totales["Junio"]+=$row_cant_cursos_andes['Junio'];
$totales["Julio"]+=$row_cant_cursos_andes['Julio'];
$totales["Agosto"]+=$row_cant_cursos_andes['Agosto'];
$totales["Septiembre"]+=$row_cant_cursos_andes['Septiembre'];
$totales["Octubre"]+=$row_cant_cursos_andes['Octubre'];
$totales["Noviembre"]+=$row_cant_cursos_andes['Noviembre'];
$totales["Diciembre"]+=$row_cant_cursos_andes['Diciembre'];
?>


<?php } while ($row_cant_cursos_andes mysql_fetch_assoc($cant_cursos_andes)); ?>

    </tr>
        <td bgcolor="#E0E0E0" colspan="2"><strong>Total x mes</strong></td>
        <td><strong><?php echo $totales["Enero"]; ?></strong></td>
        <td><strong><?php echo $totales["Febrero"]; ?></strong></td>
        <td><strong><?php echo $totales["Marzo"]; ?></strong></td>
        <td><strong><?php echo $totales["Abril"]; ?></strong></td>
        <td><strong><?php echo $totales["Mayo"]; ?></strong></td>
        <td><strong><?php echo $totales["Junio"]; ?></strong></td>
        <td><strong><?php echo $totales["Julio"]; ?></strong></td>
        <td><strong><?php echo $totales["Agosto"]; ?></strong></td>
        <td><strong><?php echo $totales["Septiembre"]; ?></strong></td>
        <td><strong><?php echo $totales["Octubre"]; ?></strong></td>
        <td><strong><?php echo $totales["Noviembre"]; ?></strong></td>
        <td><strong><?php echo $totales["Diciembre"]; ?></strong></td>
        <td colspan="3" bgcolor="E0E0E0"></td>
    </tr>
   
  </table>


Ogramar

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2660
    • Ver Perfil
Re:Suma de Filas en PHP con Metodo Do While y DB PHPMyAdmin
« Respuesta #3 en: 19 de Septiembre 2015, 17:42 »
Hola no estoy seguro de si te va a servir porque depende de cómo tengas organizados los datos.

Para obtener el valor sumatorio de una columna de una tabla de una base de datos se puede usar esta sintaxis:

SELECT SUM(nombre_columna) FROM nombre_tabla;

Por ejemplo imagina que tienes una tabla ciudades y dentro de la tabla las columnas nombre, pais, habitantes, etc.

Para obtener la suma de habitantes de todas las ciudades basta escribir:
Código: [Seleccionar]
SELECT SUM( `habitantes` )
FROM ciudades

Si no tienes los datos organizados así, puedes construir una relación temporal y asignarle nombres temporales a las columnas, y a partir de esa consulta que crea la relación temporal, aplicar la sintaxis antes mencionada. Sería lo  mismo pero con el paso intermedio de construir la relación temporal para tener los datos organizados como resulten adecuados.

Salu2

FGP

  • Sin experiencia
  • *
  • Mensajes: 10
    • Ver Perfil
    • Undergroove Beats Records
Hola, lo logre de esta manera

Estoy muy agradecido por sus ideas!!!!

Les paso código para quien lo necesite:

Código: [Seleccionar]
<?php
$conexio 
mysql_connect("localhost","root","1234");
mysql_select_db ("capacitacion"$conexio) OR die ("No se puede conectar");

//Seleccionar todos los registros
$sql="SELECT * FROM `cantidad de cursos region centro`";
$result=mysql_query($sql,$conexio);


$totalEnero 0;
$totalFebrero 0;
$totalMarzo 0;
$totalAbril 0;
$totalMayo 0;
$totalJunio 0;
$totalJulio 0;
$totalAgosto 0;
$totalSeptiembre 0;
$totalOctubre 0;
$totalNoviembre 0;
$totalDiciembre 0;

while (
$row mysql_fetch_array($result)){

$totalEnero+=$row["Enero"];
$totalFebrero+=$row["Febrero"];
$totalMarzo+=$row["Marzo"];
$totalAbril+=$row["Abril"];
$totalMayo+=$row["Mayo"];
$totalJunio+=$row["Junio"];
$totalJulio+=$row["Julio"];
$totalAgosto+=$row["Agosto"];
$totalSeptiembre+=$row["Septiembre"];
$totalOctubre+=$row["Octubre"];
$totalNoviembre+=$row["Noviembre"];
$totalDiciembre+=$row["Diciembre"];
}
//Cerrar la conexion
mysql_close($conexio);


?>


<!-- muestras los totales -->

<tr>
<td bgcolor="#E0E0E0" colspan="2"><strong>Total x mes</strong></td>
<td><strong><?php echo $totalEnero?></strong></td>
<td><strong><?php echo $totalFebrero?></strong></td>
<td><strong><?php echo $totalMarzo?></strong></td>
<td><strong><?php echo $totalAbril?></strong></td>
<td><strong><?php echo $totalMayo?></strong></td>
<td><strong><?php echo $totalJunio?></strong></td>
<td><strong><?php echo $totalJulio?></strong></td>
<td><strong><?php echo $totalAgosto?></strong></td>
<td><strong><?php echo $totalSeptiembre?></strong></td>
<td><strong><?php echo $totalOctubre?></strong></td>
<td><strong><?php echo $totalNoviembre?></strong></td>
<td><strong><?php echo $totalDiciembre?></strong></td>
<td colspan="3" bgcolor="E0E0E0"></td>
</tr>

Ogramar

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2660
    • Ver Perfil
Gracias por pasar el código, le puede ser útil a otras personas!

Salu2

 

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".