startbar
09-13-2004, 09:48 PM
hi, i have this page with a table and lots of values from a database.
How can i create totals of the different fields etc.. such as total number of tickets..
I already have a little script for totalling the whole database entry but i need some help with the more specific totallying. thanks
<!--#include virtual="/include/adovbs.inc"-->
<%
dim objConn, strCon, objRS, strSQL
Set objConn = Server.CreateObject("ADODB.Connection")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MY DATABASE"
objConn.connectionstring = strCon
objConn.Open
Set objRS = Server.CreateObject("ADODB.Recordset")
ON ERROR RESUME NEXT
Dim pageView, strNewsText
pageView=Request.Querystring("view")
%>
<html>
<head>
<title>visitors</title>
<link rel="stylesheet" href="/css/text.css" type="text/css">
</head>
<body>
<%if pageView="" THEN %>
<%
strSQL="SELECT * FROM visitors ORDER BY Date DESC"
objRS.Open strSQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF NOT objRS.EOF THEN
%>
<br>
<br><BR>
<div align="center">
<table cellpadding="0" cellspacing="0" width="100%" bgcolor="#A50A01" style="border: 0px solid #006699;">
<tr><td>
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td>
<tr>
<td><b><font class="textwhite">Date</b></td>
<td><b><font class="textwhite">Name</b></td>
<td><b><font class="textwhite">House Name/No</b></td>
<td><b><font class="textwhite">Street Name</b></td>
<td><b><font class="textwhite">Town</b></td>
<td><b><font class="textwhite">County</b></td>
<td><b><font class="textwhite">Country</b></td>
<td><b><font class="textwhite">Postcode</b></td>
<td><b><font class="textwhite">Email</b></td>
<td><b><font class="textwhite">No of Tickets</b></td>
<td><b><font class="textwhite">Printed</b></td>
<td><b><font class="textwhite">Weddings</b></td>
<td><b><font class="textwhite">Food</b></td>
<td><b><font class="textwhite">Fashions</b></td>
<td><b><font class="textwhite">Jewellery</b></td>
<td><b><font class="textwhite">Travel</b></td>
<td><b><font class="textwhite">Entertainment</b></td>
<td><b><font class="textwhite">Dating</b></td>
</tr>
<%
DO WHILE NOT objRS.EOF%>
<%if intRowColor = 0 Then
Response.Write "<TR bgcolor=""#FFFFFF"" onMouseOver=""this.bgColor = '#f5f4db'"" onMouseOut =""this.bgColor = '#FFFFFF'"">"
intRowColor = 1
Else
Response.Write "<TR bgcolor=""#ffffff"" onMouseOver=""this.bgColor = '#f5f4db'"" onMouseOut =""this.bgColor = '#FFFFFF'"">"
intRowColor = 0
End if%>
<td><font class="text"><%=objRS("Date")%></td>
<td><font class="text"><%=objRS("Name")%></td>
<td><font class="text"><%=objRS("House")%></td>
<td><font class="text"><%=objRS("Street")%></td>
<td><font class="text"><%=objRS("Town")%></td>
<td><font class="text"><%=objRS("County")%></td>
<td><font class="text"><%=objRS("Country")%></td>
<td><font class="text"><%=objRS("Postcode")%></td>
<td><font class="text"><%=objRS("Email")%></td>
<td align="center"><font class="text"><%=objRS("Tickets")%></td>
<td><font class="text"><%=objRS("Printer")%></td>
<td><font class="text"><%=objRS("Opt1")%></td>
<td><font class="text"><%=objRS("Opt2")%></td>
<td><font class="text"><%=objRS("Opt3")%></td>
<td><font class="text"><%=objRS("Opt4")%></td>
<td><font class="text"><%=objRS("Opt5")%></td>
<td><font class="text"><%=objRS("Opt6")%></td>
<td><font class="text"><%=objRS("Op7")%></td>
</tr>
<%
objRS.MoveNext
Loop
objRS.Close
%>
</table></table><BR><BR>
<font class="text"> Number of registrations = <%
'here's the connection to the mdb
Dim myConn,myPath
Set myConn = Server.CreateObject("ADODB.Connection")
myPath = Server.MapPath("DATABASE PATH")
myConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & myPath & ";"
'now we will set up an sql statement to do the counting
Dim mySQL
mySQL = "Select Count(*) AS myTotal FROM visitors"
'here's a recordset being setup to run the connection
'and to run the sql statement thus doing all our math
Dim myRS
Set myRS = Server.CreateObject("ADODB.RecordSet")
myRS.Open mySQL, myConn
'and now we write it to the page
Response.Write myRS("myTotal")
' and we ALWAYS want to close our connections and recordsets!!!
myRS.Close
Set myRS = Nothing
myConn.Close
Set myConn = Nothing
%>
<%ELSE%>
...
<%END IF%>
<%END IF%>
How can i create totals of the different fields etc.. such as total number of tickets..
I already have a little script for totalling the whole database entry but i need some help with the more specific totallying. thanks
<!--#include virtual="/include/adovbs.inc"-->
<%
dim objConn, strCon, objRS, strSQL
Set objConn = Server.CreateObject("ADODB.Connection")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MY DATABASE"
objConn.connectionstring = strCon
objConn.Open
Set objRS = Server.CreateObject("ADODB.Recordset")
ON ERROR RESUME NEXT
Dim pageView, strNewsText
pageView=Request.Querystring("view")
%>
<html>
<head>
<title>visitors</title>
<link rel="stylesheet" href="/css/text.css" type="text/css">
</head>
<body>
<%if pageView="" THEN %>
<%
strSQL="SELECT * FROM visitors ORDER BY Date DESC"
objRS.Open strSQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF NOT objRS.EOF THEN
%>
<br>
<br><BR>
<div align="center">
<table cellpadding="0" cellspacing="0" width="100%" bgcolor="#A50A01" style="border: 0px solid #006699;">
<tr><td>
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td>
<tr>
<td><b><font class="textwhite">Date</b></td>
<td><b><font class="textwhite">Name</b></td>
<td><b><font class="textwhite">House Name/No</b></td>
<td><b><font class="textwhite">Street Name</b></td>
<td><b><font class="textwhite">Town</b></td>
<td><b><font class="textwhite">County</b></td>
<td><b><font class="textwhite">Country</b></td>
<td><b><font class="textwhite">Postcode</b></td>
<td><b><font class="textwhite">Email</b></td>
<td><b><font class="textwhite">No of Tickets</b></td>
<td><b><font class="textwhite">Printed</b></td>
<td><b><font class="textwhite">Weddings</b></td>
<td><b><font class="textwhite">Food</b></td>
<td><b><font class="textwhite">Fashions</b></td>
<td><b><font class="textwhite">Jewellery</b></td>
<td><b><font class="textwhite">Travel</b></td>
<td><b><font class="textwhite">Entertainment</b></td>
<td><b><font class="textwhite">Dating</b></td>
</tr>
<%
DO WHILE NOT objRS.EOF%>
<%if intRowColor = 0 Then
Response.Write "<TR bgcolor=""#FFFFFF"" onMouseOver=""this.bgColor = '#f5f4db'"" onMouseOut =""this.bgColor = '#FFFFFF'"">"
intRowColor = 1
Else
Response.Write "<TR bgcolor=""#ffffff"" onMouseOver=""this.bgColor = '#f5f4db'"" onMouseOut =""this.bgColor = '#FFFFFF'"">"
intRowColor = 0
End if%>
<td><font class="text"><%=objRS("Date")%></td>
<td><font class="text"><%=objRS("Name")%></td>
<td><font class="text"><%=objRS("House")%></td>
<td><font class="text"><%=objRS("Street")%></td>
<td><font class="text"><%=objRS("Town")%></td>
<td><font class="text"><%=objRS("County")%></td>
<td><font class="text"><%=objRS("Country")%></td>
<td><font class="text"><%=objRS("Postcode")%></td>
<td><font class="text"><%=objRS("Email")%></td>
<td align="center"><font class="text"><%=objRS("Tickets")%></td>
<td><font class="text"><%=objRS("Printer")%></td>
<td><font class="text"><%=objRS("Opt1")%></td>
<td><font class="text"><%=objRS("Opt2")%></td>
<td><font class="text"><%=objRS("Opt3")%></td>
<td><font class="text"><%=objRS("Opt4")%></td>
<td><font class="text"><%=objRS("Opt5")%></td>
<td><font class="text"><%=objRS("Opt6")%></td>
<td><font class="text"><%=objRS("Op7")%></td>
</tr>
<%
objRS.MoveNext
Loop
objRS.Close
%>
</table></table><BR><BR>
<font class="text"> Number of registrations = <%
'here's the connection to the mdb
Dim myConn,myPath
Set myConn = Server.CreateObject("ADODB.Connection")
myPath = Server.MapPath("DATABASE PATH")
myConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & myPath & ";"
'now we will set up an sql statement to do the counting
Dim mySQL
mySQL = "Select Count(*) AS myTotal FROM visitors"
'here's a recordset being setup to run the connection
'and to run the sql statement thus doing all our math
Dim myRS
Set myRS = Server.CreateObject("ADODB.RecordSet")
myRS.Open mySQL, myConn
'and now we write it to the page
Response.Write myRS("myTotal")
' and we ALWAYS want to close our connections and recordsets!!!
myRS.Close
Set myRS = Nothing
myConn.Close
Set myConn = Nothing
%>
<%ELSE%>
...
<%END IF%>
<%END IF%>