Autor Tema: Suma de valores en campos igualdes de tres tablas distintas MySql PHPMyAdmin  (Leído 4042 veces)

FGP

  • Sin experiencia
  • *
  • Mensajes: 10
    • Ver Perfil
    • Undergroove Beats Records
Amigos tengo el siguiente inconveniente, vamos a ver quien puede echarme una mano,

Quisiera poder sumar tres tablas (con la misma estructura) las cuales tengo en una base de datos y mostrar los resultados en una tabla de totales tal y como lo tengo en un excel:

Les envio por archivo adjunto:
Imagen de lo que tengo en excel
Imagen lo que tengo realizado en PHP
Código de lo que tengo hasta el momento:

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"];

// -------------------------------LLAMADO A TABLA 01----------------------------------------- //

$maxRows_gest_cni_andes_merida 10;
$pageNum_gest_cni_andes_merida 0;
if (isset(
$_GET['pageNum_gest_cni_andes_merida'])) {
$pageNum_gest_cni_andes_merida $_GET['pageNum_gest_cni_andes_merida'];
}
$startRow_gest_cni_andes_merida $pageNum_gest_cni_andes_merida $maxRows_gest_cni_andes_merida;

mysql_select_db($database_local$local);
$query_gest_cni_andes_merida "SELECT * FROM gcni_andes_merida";
$query_limit_gest_cni_andes_merida sprintf("%s LIMIT %d, %d"$query_gest_cni_andes_merida$startRow_gest_cni_andes_merida$maxRows_gest_cni_andes_merida);
$gest_cni_andes_merida mysql_query($query_limit_gest_cni_andes_merida$local) or die(mysql_error());
$row_gest_cni_andes_merida mysql_fetch_assoc($gest_cni_andes_merida);

if (isset(
$_GET['totalRows_gest_cni_andes_merida'])) {
$totalRows_gest_cni_andes_merida $_GET['totalRows_gest_cni_andes_merida'];
} else {
$all_gest_cni_andes_merida mysql_query($query_gest_cni_andes_merida);
$totalRows_gest_cni_andes_merida mysql_num_rows($all_gest_cni_andes_merida);
}
$totalPages_gest_cni_andes_merida ceil($totalRows_gest_cni_andes_merida/$maxRows_gest_cni_andes_merida)-1;

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

// -------------------------------LLAMADO A TABLA 02----------------------------------------- //

$maxRows_gest_cni_andes_san_cristobal 10;
$pageNum_gest_cni_andes_san_cristobal 0;
if (isset(
$_GET['pageNum_gest_cni_andes_san_cristobal'])) {
$pageNum_gest_cni_andes_san_cristobal $_GET['pageNum_gest_cni_andes_san_cristobal'];
}
$startRow_gest_cni_andes_san_cristobal $pageNum_gest_cni_andes_san_cristobal $maxRows_gest_cni_andes_san_cristobal;

mysql_select_db($database_local$local);
$query_gest_cni_andes_san_cristobal "SELECT * FROM gcni_andes_san_cristobal";
$query_limit_gest_cni_andes_san_cristobal sprintf("%s LIMIT %d, %d"$query_gest_cni_andes_san_cristobal$startRow_gest_cni_andes_san_cristobal$maxRows_gest_cni_andes_san_cristobal);
$gest_cni_andes_san_cristobal mysql_query($query_limit_gest_cni_andes_san_cristobal$local) or die(mysql_error());
$row_gest_cni_andes_san_cristobal mysql_fetch_assoc($gest_cni_andes_san_cristobal);

if (isset(
$_GET['totalRows_gest_cni_andes_san_cristobal'])) {
$totalRows_gest_cni_andes_san_cristobal $_GET['totalRows_gest_cni_andes_san_cristobal'];
} else {
$all_gest_cni_andes_san_cristobal mysql_query($query_gest_cni_andes_san_cristobal);
$totalRows_gest_cni_andes_san_cristobal mysql_num_rows($all_gest_cni_andes_san_cristobal);
}
$totalPages_gest_cni_andes_san_cristobal ceil($totalRows_gest_cni_andes_san_cristobal/$maxRows_gest_cni_andes_san_cristobal)-1;

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

// -------------------------------LLAMADO A TABLA 03----------------------------------------- //

$maxRows_gest_cni_andes_vigia 10;
$pageNum_gest_cni_andes_vigia 0;
if (isset(
$_GET['pageNum_gest_cni_andes_vigia'])) {
$pageNum_gest_cni_andes_vigia $_GET['pageNum_gest_cni_andes_vigia'];
}
$startRow_gest_cni_andes_vigia $pageNum_gest_cni_andes_vigia $maxRows_gest_cni_andes_vigia;

mysql_select_db($database_local$local);
$query_gest_cni_andes_vigia "SELECT * FROM gcni_andes_el_vigia";
$query_limit_gest_cni_andes_vigia sprintf("%s LIMIT %d, %d"$query_gest_cni_andes_vigia$startRow_gest_cni_andes_vigia$maxRows_gest_cni_andes_vigia);
$gest_cni_andes_vigia mysql_query($query_limit_gest_cni_andes_vigia$local) or die(mysql_error());
$row_gest_cni_andes_vigia mysql_fetch_assoc($gest_cni_andes_vigia);

if (isset(
$_GET['totalRows_gest_cni_andes_vigia'])) {
$totalRows_gest_cni_andes_vigia $_GET['totalRows_gest_cni_andes_vigia'];
} else {
$all_gest_cni_andes_vigia mysql_query($query_gest_cni_andes_vigia);
$totalRows_gest_cni_andes_vigia mysql_num_rows($all_gest_cni_andes_vigia);
}
$totalPages_gest_cni_andes_vigia ceil($totalRows_gest_cni_andes_vigia/$maxRows_gest_cni_andes_vigia)-1;

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



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'];
?>


<!-- -----------------------------TABLA 01------------------------------------------ -->

<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
<tr bgcolor="#E0E0E0">
<td><strong>Indicador</strong></td>
<td><strong>Año</strong></td>
<td><strong>Región</strong></td>
<td><strong>CDS</strong></td>
<td><strong>Ene</strong></td>
<td><strong>Feb</strong></td>
<td><strong>Mar</strong></td>
<td><strong>Abr</strong></td>
<td><strong>May</strong></td>
<td><strong>Jun</strong></td>
<td><strong>Jul</strong></td>
<td><strong>Ago</strong></td>
<td><strong>Sep</strong></td>
<td><strong>Oct</strong></td>
<td><strong>Nov</strong></td>
<td><strong>Dic</strong></td>
<td><strong>Total</strong></td>
</tr>
<?php do { ?>
<tr>
<td bgcolor="#E0E0E0"><strong>&nbsp;&nbsp;&nbsp;<?php echo $row_gest_cni_andes_merida['Id']; ?>&nbsp;&nbsp;</strong></td>
<td><?php echo $row_gest_cni_andes_merida['year']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Region']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['CDS']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Enero']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Febrero']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Marzo']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Abril']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Mayo']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Junio']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Julio']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Agosto']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Septiembre']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Octubre']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Noviembre']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_merida['Diciembre']; ?>&nbsp; </td>
<td><strong> <?php echo $suma=$row_gest_cni_andes_merida['Enero']+ $row_gest_cni_andes_merida['Febrero']+ $row_gest_cni_andes_merida['Marzo']+ $row_gest_cni_andes_merida['Abril']+ $row_gest_cni_andes_merida['Mayo']+ $row_gest_cni_andes_merida['Junio']+ $row_gest_cni_andes_merida['Julio']+ $row_gest_cni_andes_merida['Agosto']+ $row_gest_cni_andes_merida['Septiembre']+ $row_gest_cni_andes_merida['Octubre']+ $row_gest_cni_andes_merida['Noviembre']+ $row_gest_cni_andes_merida['Diciembre'?>&nbsp; </strong></td>
</tr>
<?php } while ($row_gest_cni_andes_merida mysql_fetch_assoc($gest_cni_andes_merida)); ?>
</table>


<p>&nbsp;</p>
<p>&nbsp;</p>

<!-- -----------------------------TABLA 02------------------------------------------ -->

NO COLOCO EL CÓDIGO DE LA TABLA 2 PARA QUE NO SEA TAN LARGO

<!-- -----------------------------TABLA 03------------------------------------------ -->

<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
<tr bgcolor="#E0E0E0">
<td><strong>Indicador</strong></td>
<td><strong>Año</strong></td>
<td><strong>Región</strong></td>
<td><strong>CDS</strong></td>
<td><strong>Ene</strong></td>
<td><strong>Feb</strong></td>
<td><strong>Mar</strong></td>
<td><strong>Abr</strong></td>
<td><strong>May</strong></td>
<td><strong>Jun</strong></td>
<td><strong>Jul</strong></td>
<td><strong>Ago</strong></td>
<td><strong>Sep</strong></td>
<td><strong>Oct</strong></td>
<td><strong>Nov</strong></td>
<td><strong>Dic</strong></td>
<td><strong>Total</strong></td>
</tr>
<?php do { ?>
<tr>
<td bgcolor="#E0E0E0"><strong>&nbsp;&nbsp;&nbsp;<?php echo $row_gest_cni_andes_vigia['Id']; ?>&nbsp;&nbsp;</strong></td>
<td><?php echo $row_gest_cni_andes_vigia['year']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Region']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['CDS']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Enero']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Febrero']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Marzo']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Abril']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Mayo']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Junio']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Julio']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Agosto']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Septiembre']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Octubre']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Noviembre']; ?>&nbsp; </td>
<td><?php echo $row_gest_cni_andes_vigia['Diciembre']; ?>&nbsp; </td>
<td><strong> <?php echo $suma=$row_gest_cni_andes_vigia['Enero']+ $row_gest_cni_andes_vigia['Febrero']+ $row_gest_cni_andes_vigia['Marzo']+ $row_gest_cni_andes_vigia['Abril']+ $row_gest_cni_andes_vigia['Mayo']+ $row_gest_cni_andes_vigia['Junio']+ $row_gest_cni_andes_vigia['Julio']+ $row_gest_cni_andes_vigia['Agosto']+ $row_gest_cni_andes_vigia['Septiembre']+ $row_gest_cni_andes_vigia['Octubre']+ $row_gest_cni_andes_vigia['Noviembre']+ $row_gest_cni_andes_vigia['Diciembre'?>&nbsp; </strong></td>
</tr>
<?php } while ($row_gest_cni_andes_vigia mysql_fetch_assoc($gest_cni_andes_vigia)); ?>
</table>


</body>
</html>

<?php
mysql_free_result
($gest_cni_andes_merida);
?>

<?php
mysql_free_result
($gest_cni_andes_san_cristobal);
?>

<?php
mysql_free_result
($gest_cni_andes_vigia);
?>
« Última modificación: 20 de Septiembre 2015, 11:33 por Alex Rodríguez »

Ogramar

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2660
    • Ver Perfil
Re:Suma de tres Tablas en BD - PHPMyAdmin
« Respuesta #1 en: 16 de Septiembre 2015, 13:29 »
Hola Robinson no has puesto los link donde se pueda ver la imagen de excel ni de php

Citar
Les envio por archivo adjunto:
Imagen de lo que tengo en excel
Imagen lo que tengo realizado en PHP
Código de lo que tengo hasta el momento:

Quizás es preferible que pongas un ejemplo con pocos datos de cuáles serían los datos de partida y de qué es lo que quieres conseguir. De ese modo nos haremos una idea de cuál es el cálculo que se debe realizar.

Otra cosa: al pegar código usa siempre el botón del editor del foro #, pulsa ese botón y el código pégalo dentro de las etiquetas [ code] ... [ / code]

Salu2

FGP

  • Sin experiencia
  • *
  • Mensajes: 10
    • Ver Perfil
    • Undergroove Beats Records
Re:Suma de tres Tablas en BD - PHPMyAdmin
« Respuesta #2 en: 17 de Septiembre 2015, 06:05 »
Hola amigos, voy de nuevo con la consulta y los datos que me faltaban.

Comienzo desde cero:

1.- Tengo el siguiente archivo de excel:

Estoy intentando hacer un desarrollo web donde pueda pasar este archivo. Ya tengo creada las bases de datos por oficina ejemplo: Mérida, San Cristobal, El Vigía etc), todas las tablas son iguales y están en la misma base de datos.

2.- Ya logre hacer la consulta y mostrar estas tablas en PHP, como aparece en la siguiente imagen:

3.- No logro dar con el procedimiento para sumar estas tres tablas tal y como les muestro en el excel:

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"];

// -------------------------------LLAMADO A TABLA 01----------------------------------------- //

$maxRows_gest_cni_andes_merida 10;
$pageNum_gest_cni_andes_merida 0;
if (isset(
$_GET['pageNum_gest_cni_andes_merida'])) {
  
$pageNum_gest_cni_andes_merida $_GET['pageNum_gest_cni_andes_merida'];
}
$startRow_gest_cni_andes_merida $pageNum_gest_cni_andes_merida $maxRows_gest_cni_andes_merida;

mysql_select_db($database_local$local);
$query_gest_cni_andes_merida "SELECT * FROM gcni_andes_merida";
$query_limit_gest_cni_andes_merida sprintf("%s LIMIT %d, %d"$query_gest_cni_andes_merida$startRow_gest_cni_andes_merida$maxRows_gest_cni_andes_merida);
$gest_cni_andes_merida mysql_query($query_limit_gest_cni_andes_merida$local) or die(mysql_error());
$row_gest_cni_andes_merida mysql_fetch_assoc($gest_cni_andes_merida);

if (isset(
$_GET['totalRows_gest_cni_andes_merida'])) {
  
$totalRows_gest_cni_andes_merida $_GET['totalRows_gest_cni_andes_merida'];
} else {
  
$all_gest_cni_andes_merida mysql_query($query_gest_cni_andes_merida);
  
$totalRows_gest_cni_andes_merida mysql_num_rows($all_gest_cni_andes_merida);
}
$totalPages_gest_cni_andes_merida ceil($totalRows_gest_cni_andes_merida/$maxRows_gest_cni_andes_merida)-1;

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

// -------------------------------LLAMADO A TABLA 02----------------------------------------- //

$maxRows_gest_cni_andes_san_cristobal 10;
$pageNum_gest_cni_andes_san_cristobal 0;
if (isset(
$_GET['pageNum_gest_cni_andes_san_cristobal'])) {
  
$pageNum_gest_cni_andes_san_cristobal $_GET['pageNum_gest_cni_andes_san_cristobal'];
}
$startRow_gest_cni_andes_san_cristobal $pageNum_gest_cni_andes_san_cristobal $maxRows_gest_cni_andes_san_cristobal;

mysql_select_db($database_local$local);
$query_gest_cni_andes_san_cristobal "SELECT * FROM gcni_andes_san_cristobal";
$query_limit_gest_cni_andes_san_cristobal sprintf("%s LIMIT %d, %d"$query_gest_cni_andes_san_cristobal$startRow_gest_cni_andes_san_cristobal$maxRows_gest_cni_andes_san_cristobal);
$gest_cni_andes_san_cristobal mysql_query($query_limit_gest_cni_andes_san_cristobal$local) or die(mysql_error());
$row_gest_cni_andes_san_cristobal mysql_fetch_assoc($gest_cni_andes_san_cristobal);

if (isset(
$_GET['totalRows_gest_cni_andes_san_cristobal'])) {
  
$totalRows_gest_cni_andes_san_cristobal $_GET['totalRows_gest_cni_andes_san_cristobal'];
} else {
  
$all_gest_cni_andes_san_cristobal mysql_query($query_gest_cni_andes_san_cristobal);
  
$totalRows_gest_cni_andes_san_cristobal mysql_num_rows($all_gest_cni_andes_san_cristobal);
}
$totalPages_gest_cni_andes_san_cristobal ceil($totalRows_gest_cni_andes_san_cristobal/$maxRows_gest_cni_andes_san_cristobal)-1;

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

// -------------------------------LLAMADO A TABLA 03----------------------------------------- //

$maxRows_gest_cni_andes_vigia 10;
$pageNum_gest_cni_andes_vigia 0;
if (isset(
$_GET['pageNum_gest_cni_andes_vigia'])) {
  
$pageNum_gest_cni_andes_vigia $_GET['pageNum_gest_cni_andes_vigia'];
}
$startRow_gest_cni_andes_vigia $pageNum_gest_cni_andes_vigia $maxRows_gest_cni_andes_vigia;

mysql_select_db($database_local$local);
$query_gest_cni_andes_vigia "SELECT * FROM gcni_andes_el_vigia";
$query_limit_gest_cni_andes_vigia sprintf("%s LIMIT %d, %d"$query_gest_cni_andes_vigia$startRow_gest_cni_andes_vigia$maxRows_gest_cni_andes_vigia);
$gest_cni_andes_vigia mysql_query($query_limit_gest_cni_andes_vigia$local) or die(mysql_error());
$row_gest_cni_andes_vigia mysql_fetch_assoc($gest_cni_andes_vigia);

if (isset(
$_GET['totalRows_gest_cni_andes_vigia'])) {
  
$totalRows_gest_cni_andes_vigia $_GET['totalRows_gest_cni_andes_vigia'];
} else {
  
$all_gest_cni_andes_vigia mysql_query($query_gest_cni_andes_vigia);
  
$totalRows_gest_cni_andes_vigia mysql_num_rows($all_gest_cni_andes_vigia);
}
$totalPages_gest_cni_andes_vigia ceil($totalRows_gest_cni_andes_vigia/$maxRows_gest_cni_andes_vigia)-1;

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



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'];
?>




<!-- --------------A PARTIR DE ACÁ COMIENZA EL BODY----------------------- -->


<!-- -----------------------------TABLA 01------------------------------------------ --> 

<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
  <tr bgcolor="#E0E0E0">
    <td><strong>Indicador</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Región</strong></td>
    <td><strong>CDS</strong></td>
    <td><strong>Ene</strong></td>
    <td><strong>Feb</strong></td>
    <td><strong>Mar</strong></td>
    <td><strong>Abr</strong></td>
    <td><strong>May</strong></td>
    <td><strong>Jun</strong></td>
    <td><strong>Jul</strong></td>
    <td><strong>Ago</strong></td>
    <td><strong>Sep</strong></td>
    <td><strong>Oct</strong></td>
    <td><strong>Nov</strong></td>
    <td><strong>Dic</strong></td>
    <td><strong>Total</strong></td>
 </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#E0E0E0"><strong>&nbsp;&nbsp;&nbsp;<?php echo $row_gest_cni_andes_merida['Id']; ?>&nbsp;&nbsp;</strong></td>
      <td><?php echo $row_gest_cni_andes_merida['year']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Region']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['CDS']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Enero']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Febrero']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Marzo']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Abril']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Mayo']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Junio']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Julio']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Agosto']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Septiembre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Octubre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Noviembre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_merida['Diciembre']; ?>&nbsp; </td>
      <td><strong> <?php echo $suma=$row_gest_cni_andes_merida['Enero']+ $row_gest_cni_andes_merida['Febrero']+ $row_gest_cni_andes_merida['Marzo']+ $row_gest_cni_andes_merida['Abril']+ $row_gest_cni_andes_merida['Mayo']+ $row_gest_cni_andes_merida['Junio']+ $row_gest_cni_andes_merida['Julio']+ $row_gest_cni_andes_merida['Agosto']+ $row_gest_cni_andes_merida['Septiembre']+ $row_gest_cni_andes_merida['Octubre']+ $row_gest_cni_andes_merida['Noviembre']+ $row_gest_cni_andes_merida['Diciembre'?>&nbsp; </strong></td>
    </tr>
    <?php } while ($row_gest_cni_andes_merida mysql_fetch_assoc($gest_cni_andes_merida)); ?>
</table>


<p>&nbsp;</p>
<p>&nbsp;</p>

<!-- -----------------------------TABLA 02------------------------------------------ -->

<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
  <tr bgcolor="#E0E0E0">
    <td><strong>Indicador</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Región</strong></td>
    <td><strong>CDS</strong></td>
    <td><strong>Ene</strong></td>
    <td><strong>Feb</strong></td>
    <td><strong>Mar</strong></td>
    <td><strong>Abr</strong></td>
    <td><strong>May</strong></td>
    <td><strong>Jun</strong></td>
    <td><strong>Jul</strong></td>
    <td><strong>Ago</strong></td>
    <td><strong>Sep</strong></td>
    <td><strong>Oct</strong></td>
    <td><strong>Nov</strong></td>
    <td><strong>Dic</strong></td>
    <td><strong>Total</strong></td>
 </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#E0E0E0"><strong>&nbsp;&nbsp;&nbsp;<?php echo $row_gest_cni_andes_san_cristobal['Id']; ?>&nbsp;&nbsp;</strong></td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['year']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Region']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['CDS']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Enero']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Febrero']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Marzo']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Abril']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Mayo']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Junio']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Julio']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Agosto']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Septiembre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Octubre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Noviembre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_san_cristobal['Diciembre']; ?>&nbsp; </td>
      <td><strong> <?php echo $suma=$row_gest_cni_andes_san_cristobal['Enero']+ $row_gest_cni_andes_san_cristobal['Febrero']+ $row_gest_cni_andes_san_cristobal['Marzo']+ $row_gest_cni_andes_san_cristobal['Abril']+ $row_gest_cni_andes_san_cristobal['Mayo']+ $row_gest_cni_andes_san_cristobal['Junio']+ $row_gest_cni_andes_san_cristobal['Julio']+ $row_gest_cni_andes_san_cristobal['Agosto']+ $row_gest_cni_andes_san_cristobal['Septiembre']+ $row_gest_cni_andes_san_cristobal['Octubre']+ $row_gest_cni_andes_san_cristobal['Noviembre']+ $row_gest_cni_andes_san_cristobal['Diciembre'?>&nbsp; </strong></td>
    </tr>
    <?php } while ($row_gest_cni_andes_san_cristobal mysql_fetch_assoc($gest_cni_andes_san_cristobal)); ?>
</table>

<p>&nbsp;</p>
<p>&nbsp;</p>

<!-- -----------------------------TABLA 03------------------------------------------ -->

<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
  <tr bgcolor="#E0E0E0">
    <td><strong>Indicador</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Región</strong></td>
    <td><strong>CDS</strong></td>
    <td><strong>Ene</strong></td>
    <td><strong>Feb</strong></td>
    <td><strong>Mar</strong></td>
    <td><strong>Abr</strong></td>
    <td><strong>May</strong></td>
    <td><strong>Jun</strong></td>
    <td><strong>Jul</strong></td>
    <td><strong>Ago</strong></td>
    <td><strong>Sep</strong></td>
    <td><strong>Oct</strong></td>
    <td><strong>Nov</strong></td>
    <td><strong>Dic</strong></td>
    <td><strong>Total</strong></td>
 </tr>
  <?php do { ?>
    <tr>
      <td bgcolor="#E0E0E0"><strong>&nbsp;&nbsp;&nbsp;<?php echo $row_gest_cni_andes_vigia['Id']; ?>&nbsp;&nbsp;</strong></td>
      <td><?php echo $row_gest_cni_andes_vigia['year']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Region']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['CDS']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Enero']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Febrero']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Marzo']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Abril']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Mayo']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Junio']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Julio']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Agosto']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Septiembre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Octubre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Noviembre']; ?>&nbsp; </td>
      <td><?php echo $row_gest_cni_andes_vigia['Diciembre']; ?>&nbsp; </td>
      <td><strong> <?php echo $suma=$row_gest_cni_andes_vigia['Enero']+ $row_gest_cni_andes_vigia['Febrero']+ $row_gest_cni_andes_vigia['Marzo']+ $row_gest_cni_andes_vigia['Abril']+ $row_gest_cni_andes_vigia['Mayo']+ $row_gest_cni_andes_vigia['Junio']+ $row_gest_cni_andes_vigia['Julio']+ $row_gest_cni_andes_vigia['Agosto']+ $row_gest_cni_andes_vigia['Septiembre']+ $row_gest_cni_andes_vigia['Octubre']+ $row_gest_cni_andes_vigia['Noviembre']+ $row_gest_cni_andes_vigia['Diciembre'?>&nbsp; </strong></td>
    </tr>
    <?php } while ($row_gest_cni_andes_vigia mysql_fetch_assoc($gest_cni_andes_vigia)); ?>
</table>

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

</body>
</html>

<?php
mysql_free_result
($gest_cni_andes_merida);
?>


<?php
mysql_free_result
($gest_cni_andes_san_cristobal);
?>


<?php
mysql_free_result
($gest_cni_andes_vigia);
?>


« Última modificación: 17 de Septiembre 2015, 06:07 por Robinson Gomez »

Ogramar

  • Moderador Global
  • Experto
  • *******
  • Mensajes: 2660
    • Ver Perfil
Re:Suma de tres Tablas en BD - PHPMyAdmin
« Respuesta #3 en: 19 de Septiembre 2015, 17:51 »
Hola Robinson, no parece que estés haciendo el código todo lo limpio que debería ser porque es muy repetitivo. Tienes tres tablas con la misma estructura, entonces sería más adecuado crear una función a la que le pases el nombre de la tabla y realice las operaciones que haya que realizar. De este modo, no tendrías que repetir el código.

Ahora bien, tal y como lo tienes planteado ya tienes calculado los valores de cada tabla. ¿No te falta simplemente realizar la suma?

Por ejemplo:

Código: [Seleccionar]
$total_Andes['Enero'] = $row_gest_cni_andes_merida['Enero'] + $row_gest_cni_andes_san_cristobal['Enero'] +$row_gest_cni_andes_vigia['Enero'];
¿Y después mostrar la tabla con el valor de los sumatorios?

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".