J
Jeff
Hey gang.
I have a script that gets stats from a mssql db, and then inserts those
stats into a temp table. where i can work with them as i wish.
the problem is it isn't looping through all the records, and i am not sure
why.
i know the script isn't perfect, as it is open to sql injection and stuff
like that, but once the site is complete, i will be putting in checks and
things like that to stop it.
any ideas why it isn't looping??
<% set stats1 = conn.execute("select team_name from teams where idivision =
'ACA'")
do while not stats1.eof
varT = stats1.fields.item("team_name").value
set check1 = conn.execute("select count(teama) as cnt1 from matches
where teama = '" & varT & "'")
bam1 = check1.fields.item("cnt1").value
if bam1 = 0 then
varW1 = 0
elseif bam1 = 1 then
set stats1 = conn.execute("select teama_points from matches where
teama = '" & varT & "'")
varW1 = stats1.fields.item("teama_points").value
elseif bam1 > 1 then
set stats1 = conn.execute("select sum(teama_points) as pts1 from
matches where teama = '" & varT & "'")
varW1 = stats1.fields.item("pts1").value
end if
set check2 = conn.execute("select count(teamb) as cnt11 from matches
where teamb = '" & varT & "'")
bam2 = check2.fields.item("cnt11").value
if bam2 = 0 then
varL12 = 0
elseif bam2 = 1 then
set stats21 = conn.execute("select teamb_points from matches where
teamb = '" & varT & "'")
varL12 = stats21.fields.item("teamb_points").value
elseif bam2 > 1 then
set stats21 = conn.execute("select sum(teamb_points) as pts2 from
matches where teamb = '" & varT & "'")
varL12 = stats21.fields.item("pts2").value
end if
set stats2 = conn.execute("select count(iwinner) as wins from matches
where iwinner = '" & varT & "'")
varW2 = stats2.fields.item("wins").value
set stats3 = conn.execute("select count(iloser) as losses from matches
where iloser = '" & varT & "'")
varL1 = stats3.fields.item("losses").value
total_points = varW1 + varL12
var_total = bam1 + bam2
if bam1 = 0 then
win_pct = 0
else
win_pct = formatnumber(((bam1 / var_total)*100),0)
end if
strSQL = "insert into temp (team, points, wins, losses, win_pct)
values ('" & varT & "', " & total_points & ", " & varW2 & ", " & varL1 & ",
" & win_pct & ")"
conn.execute (strSQL)
stats1.movenext
loop
%>
I have a script that gets stats from a mssql db, and then inserts those
stats into a temp table. where i can work with them as i wish.
the problem is it isn't looping through all the records, and i am not sure
why.
i know the script isn't perfect, as it is open to sql injection and stuff
like that, but once the site is complete, i will be putting in checks and
things like that to stop it.
any ideas why it isn't looping??
<% set stats1 = conn.execute("select team_name from teams where idivision =
'ACA'")
do while not stats1.eof
varT = stats1.fields.item("team_name").value
set check1 = conn.execute("select count(teama) as cnt1 from matches
where teama = '" & varT & "'")
bam1 = check1.fields.item("cnt1").value
if bam1 = 0 then
varW1 = 0
elseif bam1 = 1 then
set stats1 = conn.execute("select teama_points from matches where
teama = '" & varT & "'")
varW1 = stats1.fields.item("teama_points").value
elseif bam1 > 1 then
set stats1 = conn.execute("select sum(teama_points) as pts1 from
matches where teama = '" & varT & "'")
varW1 = stats1.fields.item("pts1").value
end if
set check2 = conn.execute("select count(teamb) as cnt11 from matches
where teamb = '" & varT & "'")
bam2 = check2.fields.item("cnt11").value
if bam2 = 0 then
varL12 = 0
elseif bam2 = 1 then
set stats21 = conn.execute("select teamb_points from matches where
teamb = '" & varT & "'")
varL12 = stats21.fields.item("teamb_points").value
elseif bam2 > 1 then
set stats21 = conn.execute("select sum(teamb_points) as pts2 from
matches where teamb = '" & varT & "'")
varL12 = stats21.fields.item("pts2").value
end if
set stats2 = conn.execute("select count(iwinner) as wins from matches
where iwinner = '" & varT & "'")
varW2 = stats2.fields.item("wins").value
set stats3 = conn.execute("select count(iloser) as losses from matches
where iloser = '" & varT & "'")
varL1 = stats3.fields.item("losses").value
total_points = varW1 + varL12
var_total = bam1 + bam2
if bam1 = 0 then
win_pct = 0
else
win_pct = formatnumber(((bam1 / var_total)*100),0)
end if
strSQL = "insert into temp (team, points, wins, losses, win_pct)
values ('" & varT & "', " & total_points & ", " & varW2 & ", " & varL1 & ",
" & win_pct & ")"
conn.execute (strSQL)
stats1.movenext
loop
%>