Foros del Web » Programando para Internet » PHP »

Como imprimir 'esto' de la variable sum! No entiendo :s

Estas en el tema de Como imprimir 'esto' de la variable sum! No entiendo :s en el foro de PHP en Foros del Web. Bueno, yo tengo una página donde se deben sumar los valores de todos los registros de la tabla usuarios, pero se deben sumar solo los ...
  #1 (permalink)  
Antiguo 15/04/2008, 13:46
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 9 meses
Puntos: 0
Como imprimir 'esto' de la variable sum! No entiendo :s

Bueno, yo tengo una página donde se deben sumar los valores de todos los registros de la tabla usuarios, pero se deben sumar solo los que son de un mismo equipo... osea que debo sumar todos los del equipo1,equipo2,equipo3,equipo4. Tengo este codigo, lo que yo no se es como poner con un echo en el sitio la suma de cada uno:
Cita:
Conexion
HTML
PHP
Zona del problema
<?php
Conexion
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

mysql_select_db($database_PotterHispano, $PotterHispano);
$query_suma = "SELECT casa, sum( puntos_propios ) as puntos_totales FROM `usuarios` GROUP BY casa";
$suma = mysql_query($query_suma, $PotterHispano) or die(mysql_error());
$row_suma = mysql_fetch_assoc($suma);
$totalRows_suma = mysql_num_rows($suma);

?><? $_COOKIE['MM_Username'] = $usuario; ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
<link href="/estilos.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
}
-->
</style></head>

<body>
<div id="apDiv1"><iframe scrolling="no" height="1450" width="560" src="/noticias.php" name="c"></iframe></div>
<div id="apDiv2">
<div align="center">
<p><img src="/botones/puntos.png" width="150" height="50" /></p>
<table width="176" border="0">
<tr>
<td><div align="center">.:Gry:.</div></td>
<td><div align="center">.:Sly:.</div></td>
<td><div align="center">.:Huf:.</div></td>
<td><div align="center">.:Rav:.</div></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
</tr>
</table>
<p><img src="/botones/revista.png" width="150" height="50" /><img src="/botones/libros.png" width="150" height="50" /><img src="/botones/afiliados.png" width="150" height="50" /></p>
</div>
<div align="center">
<p>&nbsp;</p>
</div>
</div>
<div id="apDiv3"><img src="/botones/ph.png" width="150" height="50" /><img src="/botones/ultimas.png" width="150" height="50" /><img src="/botones/hora.png" width="150" height="50" /><img src="/botones/peliculas.png" width="150" height="50" /></div>
<table width="986" border="0" background="/layout.jpg" id="todo">
<tr>
<td height="347" colspan="3">&nbsp;</td>
</tr>
<tr>
<td height="55" colspan="3"><div align="center">Avisos para hoy: El sitio sigue en construccion.</div></td>
</tr>
<tr>
<td height="63" colspan="3"><div align="center"><a href="/index.php">Home</a> - <a href="/menuprincipal/casas.php" target="c">Casas</a> - <a href="/menuprincipal/clases.php" target="c">Clases</a> - <a href="/menuprincipal/contacto.php" target="c">Contacto</a> - <a href="/menuprincipal/copa.php" target="c">Copa</a> - <a href="/menuprincipal/staff.php" target="c">Staff</a></div></td>
</tr>
<tr>
<td height="65" colspan="3"><div align="center"><a href="/menuusuarial/hacertarea/tarea.php" target="c">Tarea</a> - <a href="/menuusuarial/notas/index.php" target="c">Notas</a> - <a href="/menuusuarial/perfil/perfil.php" target="c">Mi perfil</a> - <a href="/menuusuarial/recapitulativo/puntos.php" target="c">Puntos </a></div></td>
</tr>
<tr>
<td width="201" height="1464">&nbsp;</td>
<td width="564"><p>&nbsp;</p>
</td>
<td width="207">&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

<?php
mysql_free_result($suma);
?>



  #2 (permalink)  
Antiguo 15/04/2008, 13:57
Avatar de .php  
Fecha de Ingreso: julio-2006
Mensajes: 481
Antigüedad: 17 años, 8 meses
Puntos: 5
Re: Como imprimir 'esto' de la variable sum! No entiendo :s

yo de ti lo hago de sql.


Código PHP:
$equipo   =   array("equipo1","equipo2","equipo3","equipo4");
for (
$i 0$i<coun($equipo);$++){
   
$sql "select sum(valores) as suma from Usuarios where equipo = '$equipo[$i]'";
   
$result   =   mysql_query($sql);
   
$fila   =   mysql_fetch_object($result);
   print 
$fila->suma;
  
mysql_free_result($result);

suerte.
__________________
~~[FiDeLio]~~
  #3 (permalink)  
Antiguo 15/04/2008, 14:23
Avatar de hgp147  
Fecha de Ingreso: diciembre-2006
Ubicación: Buenos Aires, Argentina
Mensajes: 980
Antigüedad: 17 años, 3 meses
Puntos: 36
Re: Como imprimir 'esto' de la variable sum! No entiendo :s

Hola lauchalp95 para colorear el código automáticamente podés utilizar el botón:

Para código PHP

Para código HTML

Para código

La opción aparece cuando utilizas el editor en modo avanzado, para eso hace click: Ir a Avanzado
__________________
Spread Firefox | Download Day 2008
¡Únete en nuestra misión para alcanzar el Record Guinness al software más descargado en 24 horas! http://www.spreadfirefox.com/es-ES/worldrecord/
  #4 (permalink)  
Antiguo 15/04/2008, 17:18
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 9 meses
Puntos: 0
Re: Como imprimir 'esto' de la variable sum! No entiendo :s

Muchas gracias, pero no entiendo como muestro cada uno por separado?
  #5 (permalink)  
Antiguo 15/04/2008, 17:44
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 9 meses
Puntos: 0
Re: Como imprimir 'esto' de la variable sum! No entiendo :s

No me sirven esos codigos
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /www/sites/1/iespana.es/h/p/hpotterhispano/site/index.php on line 48

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /www/sites/1/iespana.es/h/p/hpotterhispano/site/index.php on line 50
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:27.