Foros del Web » Programando para Internet » ASP Clásico »

listado con suma de campos registros anteriores

Estas en el tema de listado con suma de campos registros anteriores en el foro de ASP Clásico en Foros del Web. Estoy intentando hacer este listado, cuando se produce una alta o una baja dependiendo de si el socio es un hombre o una mujer se ...
  #1 (permalink)  
Antiguo 25/03/2005, 09:33
 
Fecha de Ingreso: mayo-2003
Mensajes: 866
Antigüedad: 22 años
Puntos: 0
listado con suma de campos registros anteriores

Estoy intentando hacer este listado, cuando se produce una alta o una baja dependiendo de
si el socio es un hombre o una mujer se inserta en la base de datos un valor en los campos
balanceM y balanceH, de la siguiente forma:
Alta:
si es un hombre balanceM=0 y balanceH=1
si es una mujer balanceM=1 y balanceH=0
Baja:
si es un hombre balanceM=0 y balanceH=-1
si es una mujer balanceM=-1 y balanceH=0

Estas variables muestran los valores de lo que ha supuesto la aportacion individual de
cada individuo al Total de hombres (TOTALH) y al total de mujeres (TOTALM).

Las variablEs TOTALH Y TOTALM intento que recojan los resultados acumulados.
Los resultados estan paginados de 25 en 25, el problema es que estas variables
vuelven a inicializarse en cada pagina, mostrando tan solo el acumulado de los registros mostrados
en cada pagina, en lugar de tambien tener en cuenta los registros precedentes.

¿Podria modificar la consulta poniendo Sum (balanceM) As TOTALM y Sum (balanceH) As TOTALH?
Creo que si pero no se como seria la forma correcta de realizar la consulta.
¿Se os ocurre otra forma?

El archivo db.asp contiene:
<!-- #include file="adovbs.inc" -->
<%
dim db
dim strConn
strConn = "sociosconn"
Set db = Server.CreateObject("ADODB.Connection")
db.open strConn
%>


<%@ LANGUAGE = "VBScript" %>
<!-- #include file="db.asp" -->
<%Response.expires=-1500%>
<html lang="ES">
<head>
<META HTTP-EQUIV="expires" content="0">
<META HTTP-EQUIV="cache-control" content="no-cache">
<META HTTP-EQUIV="pragma" content="no-cache">
<LINK href="estilos.css" rel=stylesheet>
</head>
<body link="#000000" vlink="#000000" alink="#000000">
<table border="0,2" bordercolor="#000000" align="center">
<tr>
<td align="center" class="textopeqcolor">
<b>NUMERO DE SOCIO</b></td>
<td valign="top" align="center" class="textopeqcolor">
<b>Balance</b><br><br>
<table width="10%">
<tr><td align="center" class="textopeqcolor">
<b>HOMBRES</b></td>
<td align="center" class="textopeqcolor">
<b>MUJERES</b></td>
</tr>
</table>
</td>
<td valign="top" align="center" class="textopeqcolor">
<b>TOTAL</b><br><br>
<table width="10%">
<tr><td align="center" class="textopeqcolor">
<b>HOMBRES</b></td>
<td align="center" class="textopeqcolor">
<b>MUJERES</b></td>
</tr>
</table>
</td>
</tr>
<%
DIM mySQL, objRS
mySQL = "SELECT * FROM SOCIOS ORDER BY idocio ASC"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorType = 1
objRS.Open mySQL, db

DIM intPageRecords, intRecords, intRecordCount, intCurrentPage
DIM intNumberOfPages, intDisplayPage
intPageRecords = Request.Querystring("pagina")
IF intPageRecords = "" THEN intPageRecords = 1 : intRecords = 1
intRecords = intPageRecords
intPageRecords = ((intPageRecords - 1) * 25) +1
intRecordCount = 0
IF NOT objRS.EOF THEN
objRS.Move (intPageRecords - 1)
DO WHILE intRecordCount < 25 and NOT objRS.EOF
%>
<tr>
<td align="center" class="textopeq">
<b><%=objRS("nidentificacion") %></b>&nbsp;&nbsp;&nbsp;
</td>
<td align="center" class="textopeq">
<table width="10%">
<tr>
<td align="center" class="textopeq">
<b><%=objRS("balanceM") %></b>
</td>
<td align="center" class="textopeq">
<b><%=objRS("balanceH") %></b>
</td>
</tr>
</table>
</Td>
<td align="center" class="textopeq">
<table width="10%">
<tr>
<td align="center" class="textopeq">
<%TOTALM=TOTALM+objRS("balanceM") %>
<b><%=TOTALM%></b>
</td>
<td align="center" class="textopeq">
<%TOTALH=TOTALH+objRS("balanceH")%>
<b><%=TOTALH%></b>
</td>
</tr>
</table>
</Td>
<%
objRS.MoveNext
intRecordCount = intRecordCount +1
Loop
END IF
%>
</table>
<table align="center">
<tr><td>
<br>
<b>
Mostrando desde el registro Nº
<%=intPageRecords%>
hasta el registro Nº
<%=intPageRecords+(intRecordCount-1)%>
<br>
<center>Total Registros:
<%=(objRS.RecordCount)%>
</center>
</b>
<p>
</td></tr>
</table>
<table align="center">
<tr><td>
<b>
<%
intCurrentPage = Request.Querystring("pagina")
IF intCurrentPage = "" THEN intCurrentPage = 1
intNumberOfPages = int(objRS.RecordCount \ 25)
IF objRS.RecordCount MOD 25<> 0 THEN intNumberOfPages = intNumberOfPages + 1
Response.Write("Página: [")
FOR intDisplayPage = 1 TO intNumberOfPages
IF Cint(intDisplayPage) = Cint(intCurrentPage) THEN
Response.Write " <b>" & intDisplayPage & "</b> "
ELSE
Response.Write " <a href=""liSTSUM.asp?pagina=" & intDisplayPage & """>" & intDisplayPage &_
"</a> "
END IF
NEXT
Response.Write ("]")
%>
</b>
</td></tr>
</table>
</body>
</html>
<%
db.close
set db=nothing
%>
  #2 (permalink)  
Antiguo 25/03/2005, 15:59
 
Fecha de Ingreso: mayo-2003
Mensajes: 866
Antigüedad: 22 años
Puntos: 0
Alguna idea?
  #3 (permalink)  
Antiguo 25/03/2005, 17:46
Avatar de sjam7  
Fecha de Ingreso: diciembre-2001
Ubicación: Guadalajara, Mexico
Mensajes: 3.672
Antigüedad: 23 años, 4 meses
Puntos: 16
que quieres hacer? me perdi en tanto codigo, contar hombres y mujeres? o que?
  #4 (permalink)  
Antiguo 26/03/2005, 02:46
 
Fecha de Ingreso: mayo-2003
Mensajes: 866
Antigüedad: 22 años
Puntos: 0
Exacto sjam7, quiero contar el total de hombres y mujeres
que llevo en cada registro.
La cosa se complica por el tema de la paginacion de registros, ademas necesito que se pueda haceder a cada pagina de resultados de forma directa y pueda ver los resultados correctos.
Estoy totalmente bloqueado, cualquier ayuda se agradece

Última edición por sqa212; 26/03/2005 a las 04:19
  #5 (permalink)  
Antiguo 26/03/2005, 05:34
 
Fecha de Ingreso: mayo-2003
Mensajes: 866
Antigüedad: 22 años
Puntos: 0
He suprimido codigo relacionado con la presentacion, para que se vea mas claro.
He creado la funcion numeroHM para intentar ver la suma de hombres y mujeres hasta el registro actual,
por una parte falla en algo porque en el primer registro de cada pagina no me muestra nada, y
por otra parte no creo que esta sea la forma correcta de hacer lo que quiero, porque hace mucho uso
de los recursos, ya que realiza una nueva consulta para cada registro.
¿Por que no me muestra el primer registro?
¿Alguna otra forma mas eficiente?
<%
function numeroHM(idsocio)

dim sql, rs

TotalH= 0
TotalM= 0

sql = "select sum (BalanceH) as TotalH,sum (BalanceM) as TotalM from reproductores where idsocio<=" & idsocio
set rs = Db.Execute(sql)
if not (rs.BOF and rs.EOF) then
TotalH = rs.Fields("TotalH").Value
TotalM = rs.Fields("TotalM").Value
end if
rs.close
set rs=Nothing
end function
%>

<%
DIM mySQL, objRS
mySQL = "SELECT * FROM socios ORDER BY idsocio ASC"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorType = 1
objRS.Open mySQL, db

DIM intPageRecords, intRecords, intRecordCount, intCurrentPage
DIM intNumberOfPages, intDisplayPage
intPageRecords = Request.Querystring("pagina")
IF intPageRecords = "" THEN intPageRecords = 1 : intRecords = 1
intRecords = intPageRecords
intPageRecords = ((intPageRecords - 1) * 25) +1
intRecordCount = 0
IF NOT objRS.EOF THEN
objRS.Move (intPageRecords - 1)
DO WHILE intRecordCount < 25 and NOT objRS.EOF
%>
<%=objRS("balanceM") %>
<%=objRS("balanceH") %>
<%idsocio=objRS("idsocio") %>
<%=numeroHM(idsocio)%>
<%=TotalM%>
<%=TotalH%>

<%
objRS.MoveNext
intRecordCount = intRecordCount +1
Loop
END IF
%>

<%
intCurrentPage = Request.Querystring("pagina")
IF intCurrentPage = "" THEN intCurrentPage = 1
intNumberOfPages = int(objRS.RecordCount \ 25)
IF objRS.RecordCount MOD 25<> 0 THEN intNumberOfPages = intNumberOfPages + 1
Response.Write("Página: [")
FOR intDisplayPage = 1 TO intNumberOfPages
IF Cint(intDisplayPage) = Cint(intCurrentPage) THEN
Response.Write " <b>" & intDisplayPage & "</b> "
ELSE
Response.Write " <a href=""liSTSUM.asp?pagina=" & intDisplayPage & """>" & intDisplayPage &_
"</a> "
END IF
NEXT
Response.Write ("]")
%>
</body>
</html>
<%
db.close
set db=nothing
%>
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 11:14.