
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.
<?php mysql_free_result($cant_cursos_andes);?>

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> </p>
<p> </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']; ?> </a></strong></td>
<td><?php echo $row_cant_cursos_andes['year']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Enero']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Febrero']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Marzo']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Abril']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Mayo']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Junio']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Julio']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Agosto']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Septiembre']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Octubre']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Noviembre']; ?> </td>
<td><?php echo $row_cant_cursos_andes['Diciembre']; ?> </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'] ?>
</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) ?> </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);?>

Valora esta pregunta


0