Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    Stockholm, Sweden
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Average Score Count Script Error -Solved

    Hi,

    I'm trying to add a new row with a script that counts the average score for each competition to a table in a loop but I don't get it to work.
    First of all I placed it outside the loop and that's the only place I can see it should be in so I need help on how to get it inside the loop.

    The loop ends in row 81-82 and my new row (script) is placed in row 86-98

    My other question probably solves itself if the first question is solved I guess
    because the thing is that where I placed my new row made it just show up after the last table and I want it to show last in each table thatis looped out
    from the database.

    You can see how it looks here: http://www.monow.se/borg/sub/test.asp

    Someone who could tell me what to do??
    /Speedy

    and here is the code:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    	<head>
    
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    	<title></title>
    	<script language="JavaScript" type="text/javascript" src="/templates/menu.js"></script>
    	<link href="stylesheets/stylesheet1.css" rel="stylesheet" type="text/css" >
    	<link href="stylesheets/links.css" rel="stylesheet" type="text/css" >
    	<link rel="stylesheet" type="text/css" href="stylesheets/table.css">
    	</head>
    
    <body>
    
    
    
                    
                    <table width="695" height="0" border="0" cellspacing="5">
                      <tr>
                        <td>
                          <%
                            Sub createNewTableStart(endPrevTable)
    	                if endPrevTable then response.write vbCrLf & "</table>" & vbCrLf & "<br />" & vbCrLf
                          %>
    
                          <span style="padding-left: 28px;" class="rubrik"><b><%=objrs("CompName") %>&nbsp;<%= objrs("Course") %> (<%= objrs("Date") %>)</b></span>
    
                          <br>
                          <table align="center" border="1" style="border-collapse: collapse" bordercolor="1px solid #000000">
                            <tr bgcolor="#CDD5E4" style="font-weight: bold">
                              <% For I = 1 to 18 %>
                              <td width="30" align="center"><a href="top10.asp?Show=Top10&Lane=<%=I%>" target=""><%=I%></a></td>
                                <% Next %>
                                <td width="30" align="center">Tot</td>
                            </tr>
                            <%
                              End Sub
                            %>
    
                            <%
                              dim Conn, objrs, i, y, prevDate, currDate, strTot
                              Set Conn = Server.CreateObject("ADODB.Connection") 
                              Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/eb.mdb") 
                              Set objrs = Conn.Execute("SELECT tbl_player.Namn, tbl_player.Efternamn, tbl_res.CompYear, tbl_res.Course, tbl_res.AMT1, tbl_res.AMT2, tbl_res.AMT3, tbl_res.AMT4, tbl_res.AMT5, tbl_res.AMT6, tbl_res.AMT7, tbl_res.AMT8, tbl_res.AMT9, tbl_res.AMT10, tbl_res.AMT11, tbl_res.AMT12, tbl_res.AMT13, tbl_res.AMT14, tbl_res.AMT15, tbl_res.AMT16, tbl_res.AMT17, tbl_res.AMT18, tbl_res.TOTAL, tbl_res.Date, tbl_res.CompName FROM tbl_player INNER JOIN tbl_res ON tbl_player.PlayerId=tbl_res.PlayerId WHERE tbl_res.Surface ='EB' ORDER BY tbl_res.Date, tbl_res.Varv")
    
    
                              y=0
                              while not objrs.BOF and not objrs.EOF
                                currDate = objrs("Date")
                                if IsEmpty(prevDate) then 'first iteration
    	                      createNewTableStart(false)
                                elseif prevDate <> currDate then
    	                      createNewTableStart(true)
                                end if
                                y = y + 1
                                If y Mod 2 = 0 Then
                              %>
                              <tr bgcolor="#EEEEEE">
                              <% Else %>
                              <tr bgcolor="#FFFFFF">
                              <% End If %>
    	
    	                  <% For I = 1 to 18 %>
    	                  <td align="center"><%=objrs("AMT" & I)%></td>
                              <% Next %>
    	                  <td align="center">
    	                  <% 
    	                    strTot = objrs("TOTAL")
    	                    if strTot < 20 then 
    		              response.write "<span class=""blueText"">"&strTot&"</span>"
    	                    elseif strTot < 25 then 
    		              response.write "<span class=""greenText"">"&strTot&"</span>"
    	                    elseif strTot < 30 then
    		              response.write "<span class=""redText"">"&strTot&"</span>"
    	                    elseif strTot > 29 then
    		              response.write "<span class=""blackText"">"&strTot&"</span>"
    	                    End if 	
    	                    response.write vbCrLf & "</td>" & vbCrLf & "</tr>" & vbCrLf
    	                    prevDate = currDate
    	                    objrs.movenext
                                wend
                                if i=0 then 'empty recordset
                                  response.write "<tr><td colspan=""19"">Det finns inga resultat!</td></tr>"
                                end if
                              %>
                              <tr>
                                <td colspan="18">&nbsp;</td>
                                <td>
                                  <% set antalV = Conn.Execute("SELECT tbl_res.Comp_Name, Count(tbl_res.TOTAL) AS Ant FROM tbl_res GROUP BY tbl_res.Comp_Name HAVING tbl_res.Comp_Name='"&objrs("Comp_Name")&"'")%>
    	                      <% Set snitt = Conn.Execute("SELECT tbl_res.Comp_Name, Sum(tbl_res.TOTAL) AS Summa FROM tbl_res GROUP BY tbl_res.Comp_Name HAVING tbl_res.Comp_Name='"&objrs("Comp_Name")&"'")%>
    
    	                      <% inSvar1 = snitt("Summa")
    	                         inSvar2 = AntalV("Ant")
    	                         inSvar = Insvar1 / Insvar2
    	                         Response.Write formatnumber(Insvar,1) 
                                  %>
                                </td>
                              </tr>
                            </table>
                            <%
                              'close and kill recordset/connection objects
                              objrs.close
                              set objrs = nothing
                              Conn.close
                              set Conn = nothing
                            %>
                        </td>
                      </tr>
                    </table>
                    
                    
    
    
                  </td>
    
                </tr>
              </table>
    </body>
    </html>
    Last edited by Speedy; 03-04-2006 at 05:06 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •