ASP position question

J

Jeff

Ok gang, I am going to try and explain my question.

I have a page where a person's position is listed. This is what I am using
to get that position.
I first sort by the round field in the DB, then I display the table on the
page. The problem I have is, if there are say 2 people with the same round
number, it continue's counting. For example
http://65.61.20.190/GIG/ladder/main.asp

see how the 4th and 5th place show the same number of laps )that is the
number in the round field in the DB), what I want is to show both of them
with a 4. here is my script:


<%
set admin1 = conn.execute ("SELECT * FROM rounds where round > 0 ORDER
BY round DESC,username ASC")

%>
<div align="center">
<center>
<table border="0" cellpadding="2" style="border-collapse: collapse"
width="27%" id="AutoNumber1">
<tr>
<td width="100%" colspan="3">
<p align="center"><b>GIG Ladder Lap Count</b></td>
</tr>
<tr>
<td width="50%" align="center" nowrap><b><font
size="4">Pos</font></b></td>
<td width="50%" align="center" nowrap><b><font
size="4">Name</font></b></td>
<td width="50%" align="center" nowrap><b><font
size="4">Laps</font></b></td>
</tr>
<%
game = 1
do while not admin1.eof
var1 = admin1.fields.item("round").value
var2 = admin1.fields.item("username").value
%>

<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=game%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=var2%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=var1%></font></b></td>
</tr>
<%
game = game + 1
admin1.movenext
loop
%>
</table>

as you can see game is the position column in the displayed table.
How can I have it show the same pos for a number that is the same, but
continue counting as if they were NOT the same. Meaning, if there was a
person below them, they would be in 6th place, since 2 are tied for 4th?
I hope this makes sense
Please help
Bam
 
J

Jevon

One method of doing this would be to add/change a couple of variables:
numLastValue, numRealPos, numDisplayPos

Initialise with numRealPos = 0 and numDisplayPos = 1

Then, inserted near the start of each loop:
numRealPos = numRealPos + 1
If Not var1 = numLastValue Then
numLastValue = var1
numDisplayPos = numRealPos
End If

You then output numDisplayPos in place of game.

I'd recommend giving your variables meaningful names - e.g. numRound rather
than var1, rsRoundResults rather than admin1, etc - makes life a lot easier
when your pages get more complex. Also, you should avoid SELECT * in
database queries - http://www.aspfaq.com/show.asp?id=2096

Jevon
 
J

Jeff

thanks for the reply. is this what you mean:

<%
numRealPos = 0 and numDisplayPos = 1
do while not admin1.eof
var1 = admin1.fields.item("round").value
var2 = admin1.fields.item("username").value
%>

<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=numDisplayPos%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=var2%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=var1%></font></b></td>
</tr>
<%
numRealPos = numRealPos + 1
If Not var1 = numLastValue Then
numLastValue = var1
numDisplayPos = numRealPos
End If
admin1.movenext
loop
%>

if so, the output still isn't correct:
http://www.gig-golf.com/GIG/ladder/main3.asp
the first position is 0 and 3 and 4 would be incorrect.
please advise
Bam
ps
i will take your advice in naming things. I do see what you mean, as to how
it can become confusing later.
 
J

Jevon

Close:

<%
numRealPos = 0
numDisplayPos = 1
do while not admin1.eof
admin1.movenext
var1 = admin1.fields.item("round").value
var2 = admin1.fields.item("username").value
numRealPos = numRealPos + 1
If Not var1 = numLastValue Then
numLastValue = var1
numDisplayPos = numRealPos
End If
%>
<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=numDisplayPos%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=var2%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=var1%></font></b></td>
</tr>
<%
loop
%>

Should give what you want.

Jevon
 
J

Jeff

thanks a bunch. I did have to move the admin1.movenext
down by the loop for it to work. but when I did that, all was fine.
again, thanks a bunch. I learned quite a bit from this.

Bam
 
J

Jevon

Whoops, yeah, that should have been left at the end of the loop. Doh!

Glad I could help.

Jevon
 
J

Jeff

The solution you gave worked great, but now I have something more to add.
Is there a way to tell the script, that if 2 places do have the same number,
that it would put a T there? Like T4 meaning tied for 4th place?
 
J

Jevon

Yeah it's possible - requires a few more variables though, and adjustment of
the loop.
(Pseudocode)

<%
If Not admin1.EOF Then
numRealPos = 1
numDisplayPos = 1
boolTied = false
numLastRound = admin1.fields.item("round").value
strLastUsername = admin1.fields.item("username").value
admin1.movenext
do while not admin1.eof
numThisRound = admin1.fields.item("round").value
strThisUsername = admin1.fields.item("username").value
If Not numLastRound = numThisRound Then
boolTied = false
Else
boolTied = true
End If
%>
<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%
If boolTied = True Then
Response.Write "T"
End If
Response.Write numDisplayPos
%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=strLastUsername%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=numLastRound%></font></b></td>
</tr>
<%
If Not numLastRound = numThisRound Then
numLastRound = numThisRound
numDisplayPos = numRealPos
End If

strLastUserName = strThisUserName
numRealPos = numRealPos + 1

admin1.movenext
loop
%>
<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%
If boolTied = True Then
Response.Write "T"
End If
Response.Write numDisplayPos
%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=strLastUsername%></font></b></td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=numLastRound%></font></b></td>
</tr>
<%
End If
%>


I think something like that will do what you want - expect a few syntax
errors and possible logic errors though. It's not particularly tidy, and
there may be better ways to achieve what you want, but it's a start :)

Jevon
 
J

Jeff

Hey Jevon. Sorry it took so lang to get back.
It works/isn't working.
let me show you what it is doing.
http://www.gig-golf.com/GIG/ladder/current2.asp

now let me show you the script I have. I had to make changes to what you
gave, in order to fit it right. But anyway:

<%
Set standings_player = Conn.Execute("SELECT * FROM rounds where total_score
5 ORDER BY total_score DESC, username ASC")

If Not standings_player.EOF Then
numRealPos = 1
numDisplayPos = 1
boolTied = false
numLastRound = standings_player.fields.item("total_score").value
strLastUsername = standings_player.fields.item("username").value
standings_player.movenext
do while not standings_player.eof
numThisRound = standings_player.fields.item("total_score").value
strThisUsername = standings_player.fields.item("username").value
If Not numLastRound = numThisRound Then
boolTied = false
Else
boolTied = true
End If
%>




<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%
If boolTied = True Then
Response.Write "T"
End If
Response.Write numDisplayPos
%></font></b>&nbsp;</td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=strLastUsername%></font></b>&nbsp;</td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=numLastRound%></font></b>&nbsp;</td>
</tr>
<%
If Not numLastRound = numThisRound Then
numLastRound = numThisRound
numDisplayPos = numRealPos
End If

strLastUserName = strThisUserName
numRealPos = numRealPos + 1

standings_player.movenext
loop
%>
<tr>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%
If boolTied = True Then
Response.Write "T"
End If
Response.Write numDisplayPos
%></font></b>&nbsp;</td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=strLastUsername%></font></b>&nbsp;</td>
<td width="50%" align="center"><b><font size="4"
color="#C0C0C0"><%=numLastRound%></font></b>&nbsp;</td>
</tr>
<%
End If
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top