PHP - Sumar Filas de una Tabla en DB con PHP

 
Vista:
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 12/09/2015 07:08:41
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:

Nota: También envío .RAR con la imagen para que lo vean de manera gráfica.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?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);
 
 
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>
<meta charset="utf-8">
<title>Capacitación</title>
 
 
<body>
 
	<h2 align="center" class="header"><strong>Región Andes</strong>
	</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
 
<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 $prom=
 
round($prom, 1) ?>&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)); ?>
 
<!-- ------------------------------- Aqui quisiera realizar la suma----------------------------------------- -->
 
<table border="1" align="center" bgcolor="#CBCBCB" width="1280">
	</tr>
		<td><strong>Total</strong></td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
		<td>	</td>
	</tr>
</table>
 
<!-- -------------------------------Termina Suma de Filas----------------------------------------- -->
 
 
<p align="center">Gerencia de Capacitación ®</p>
 
</body>
</html>

<?php mysql_free_result($cant_cursos_andes);?>
Tabla-Consulta-Suma
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Sumar Filas de una Tabla en DB con PHP

Publicado por xve (6935 intervenciones) el 12/09/2015 11:11:40
Hola Robinson, la manera que yo lo haria, seria creando un array con 12 valores, y ahi ir sumando los valores... algo así:

1
2
3
totales["Enero"]+=$row_cant_cursos_andes['Enero'];
totales["Febrero"]+=$row_cant_cursos_andes['Febrero'];
...

De esta manera, vas sumando en un array los valores de cada mes, para luego en la linea de los totales, simplementes mostrar:
1
echo totales["Enero"]; // aqui tendras el total de los meses de enero.


No se si es esto exactamente lo que buscas... coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 12/09/2015 17:56:34
Hola muchas gracias por responder,
Realice lo que me sugieres, sin embargo me indica en todos los campos el numero cero, por lo que no esta sumando,
Lo habré realizado bien?

Les envío el código con las modificaciones realizadas y el resultado en el explorador:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?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);
 
 
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>
 
<body>
 
<p>&nbsp;</p>
	<h2 align="center" class="header"><strong>Región Andes</strong>
	</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
 
<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 $prom= round($prom, 1) ?>&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)); ?>
 
<!-- --------------- Aqui quisiera realizar la suma-------------- -->
<?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>Años</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>
	</tr>
</table>
 
<!-- -----------------Termina Suma de Filas------------------------ -->
 
 
<p align="center">Gerencia de Capacitación ®</p>
 
</body>
</html>
 
<?php mysql_free_result($cant_cursos_andes);?>
Tabla-Consulta-Suma-02
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Sumar Filas de una Tabla en DB con PHP

Publicado por xve (6935 intervenciones) el 12/09/2015 20:58:51
Hola Robinson, tienes que hacer la suma dentro del bucle do {} while, que es cuando tienes los valores...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 13/09/2015 01:56:31
Hola muy bien, me lo imagine,
Lo intente realizar pero creo que no esta bien realizado, adicional no se si se debe realizar un llamado a la base de datos, envío para ver si me pueden orientar:

Agradecido de antemano,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?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);
 
 
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'];
?>
 
<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 $prom= round($prom, 1) ?>&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 = mysql_fetch_assoc($cant_cursos_andes)); ?>
<!-- -------------------------------Termina Suma de Filas----------------------------------------- -->
 
<p align="center">Gerencia de Capacitación ®</p>
 
</body>
</html>

<?php mysql_free_result($cant_cursos_andes);?>
Tabla-Consulta-Suma-03
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Sumar Filas de una Tabla en DB con PHP

Publicado por xve (6935 intervenciones) el 13/09/2015 10:08:35
Robinson, sigue estando fuera del bucle!!!

Seria algo así:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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 $prom= round($prom, 1) ?>&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
	$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)); ?>
 
<!-- muestras los totales -->
</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>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 13/09/2015 15:02:30
Excelente, super agradecido por el apoyo,

Como podrán observar estoy comenzando en la programación, razón por lo cual me motivé en venir al foro.
Cuando logre ganar más conocimientos espero ser yo quien pueda ayudar,

Les dejo la imagen como quedó...!!!

Saludos,


Tabla-Consulta-Resultado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 14/09/2015 02:42:02
Buenas amigos,

Todo va bien, sin embargo todo lo que coloco en el año 2012 me lo duplica en el total de la suma

Coloque el código tal y como me sugirieron:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?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="#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 $prom= round($prom, 1) ?>&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
	$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)); ?>
 
<!-- muestras los totales -->
</tr>
	<td><strong>Total</strong></td>
	<td></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></td>
	<td></td>
	<td></td>
</tr>
 
  </table>
Tabla-Consulta-Resultado-Duplicado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 15/09/2015 19:08:33
Buenas amigos,

Todo va bien, sin embargo todo lo que coloco en el año 2012 me lo duplica en el total de la suma
Agradezco me puedan apoyar

Tabla-Consulta-Resultado-Duplicado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Sumar Filas de una Tabla en DB con PHP

Publicado por xve (6935 intervenciones) el 15/09/2015 20:19:58
Hola Robinson, ya se cual es el problema!!!

Tu haces do {}while(), eso quiere decir, que pasa una vez mas por el bucle...

Prueba ha haber while(){}
1
2
3
4
while ($row_cant_cursos_andes = mysql_fetch_assoc($cant_cursos_andes))
{
    Aqui el código
}

Coméntanos, ok?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 15/09/2015 23:27:20
Hola, haciendo lo que me sugieres tenemos que ahora solo me trae los datos del año 2012

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!-- Código que trae la DB  -->
 
 <?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 $prom= round($prom, 1) ?>&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)); ?>
 
 
 
<!-- Código para muestrar los totales -->
 
<?php while ($row_cant_cursos_andes = mysql_fetch_assoc($cant_cursos_andes)); { ?>
 
	<?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 }  ?>
 
 
    </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>

Tabla-Consulta-Resultado-Duplicado-2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 18/09/2015 04:36:15
Hermanos aun no logro dar con la solución de mi problema, tendrán alguna sugerencia?

Saludos!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alberto
Val: 478
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Sumar Filas de una Tabla en DB con PHP

Publicado por Alberto (351 intervenciones) el 18/09/2015 19:44:05
Hola...

Ammm... Yo lo haría de la siguiente manera ^^...

1
2
3
4
5
6
7
8
$totalEnero = 0;
$totalFebrero = 0;
$result = mysqli_query($conexion,"SELECT * FROM cantidades");
while ($row = mysqli_fetch_array($result)){
	$totalEnero+=$row["Enero"];
	$totalFebrero+=$row["Febrero"];
}
echo "<b>Total ENERO:</b> ".$totalEnero." <b>Total FEBRERO:</b> ".$totalFebrero;

Sin mas que comentar, cualquier duda y/o inconveniente, aquí estamos. Suerte!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 21/09/2015 22:41:01
Saben, me funciona con haciendo while {}, sin embargo debo colocarlo de primero en el codigo por lo cual me daña el cuadro.

La verdad me surge la siguiente duda: En una pagina de código, no pueden existir un bucle Do While y posterior un While?


Con-el-Bucle-While-debajo-del-Bucle-Do-While-Web
Con-el-Bucle-While-arriba-del-Bucle-Do-While-Web

Les paso por adjunto el código cuando lo coloco encima el While {} del Do While y otro cuando dejo el While {} Debajo del Do While
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 21/09/2015 22:43:20
Estimado, me funciona con haciendo while {}, sin embargo debo colocarlo de primero en el codigo por lo cual me daña el cuadro.

La verdad me surge la siguiente duda: En una pagina de código, no pueden existir un bucle Do While y posterior un While?

Con-el-Bucle-While-arriba-del-Bucle-Do-While-Web
Con-el-Bucle-While-debajo-del-Bucle-Do-While-Web

Les paso por adjunto el código cuando lo coloco encima el While {} del Do While y otro cuando dejo el While {} Debajo del Do While
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Robinson

Sumar Filas de una Tabla en DB con PHP

Publicado por Robinson (41 intervenciones) el 22/09/2015 16:27:03
Hermano Alberto eres un Capo!!!

Me sirvio como lo mencionaste...!!!

Les paso código para quien lo necesite:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?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>

Solucion

Muchas gracias a todos por sus aportes!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar