Hi, Small headache problem with a highscore table.
I have a table that displays a list of highscores. The code pulls the data from the sql table in the correct order highest score to the lowers score via the "order by score desc" tag.
It repeats the region with no problems and all the information is populating the correct table cell.
The scores are being displayed in descending order so I need to find a way to display the ranking of each row. Is there some simple mathematical coding I can place in the the first column that will add a place each time a new score is entered and rearragnge the ranking.
eg.
currently
simon 22.4
gary 22
steven 21
what i want is..
1 simon 22.4
2 gary 22
3 steven 21
and if paul comes along and scores 22.5
1 paul 22.5
2 simon 22.4
3 gary 22
4 steven 21
any help would be much appreciated.
Thanks
6 4607
I am assuming that when a new score is entered, it is getting stored into the table, and then the query runs again and prints out the scores. In order to print out the scores you must have some kind of loop that you are using to keep cycling through the table to get all the entries. So can you just set up a variable to count for you, and just echo that variable in the place you want the number to appear.
Start out with...
Before the loop begins, then at the end of the loop, by that I mean the last thing the loop does before starting over just increment that variable...
And then just echo out $i when or where you want that number to be.
I would think something like this would work. Hope it helps!
Thats works on the first page. Thanks, although when the next page of results are pulled up it starts from 1 again.
Is there a way the number can be carried on to the next page?
thanks again
Thats works on the first page. Thanks, although when the next page of results are pulled up it starts from 1 again.
Is there a way the number can be carried on to the next page?
thanks again
Hey, no fair...you didn't say that in the first post.. :D
So, you are displaying something like 25 per page or something like that? I don't know the code your using, but is it possible for you to pass the variable, or use a variable that you are already passing to setup your counter?
I guess the question I have for you is how is your script knowing what part of the list to display, and is it possible to use that info to setup the counter.
Heya, CW.
Minor thing, but ++$i is a tad bit faster than $i++.
Instead of having $i start at 1, have it start at $offset + 1, where $offset is the offset value you use in your SQL query.
Sorry to pass on the bad news about the multiple pages...
Got some more news for you. Could be good might be bad.. Its written using Dreamweaver and its lovely Recordsets.
I thought about passing the value through the Recordset Navigation bar but that may cause problems if users decide to view the last records (7 or 8 pages down the line). I suppose it may be possible to do a Count of the full amount of entries and the subtract the amount viewable on the last page and start the count from there...
OR
Get rid of the "View last" option.... (sounds good to me).
Maybe if I passed the value from the previous page to the next it might work but that posses another problem. I haven't a clue how to go about it..
Here's the trimmed down code anyways: -
<table width="30%" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td>Rank</td>
-
<td>Score</td>
-
<td>Name</td>
-
</tr>
-
<?php
-
$i=1;
-
do { ?>
-
<tr>
-
<td><? echo $i ?></td>
-
<td><?php echo $row_Recordset1['score']; ?></td>
-
<td><?php echo $row_Recordset1['name']; ?></td>
-
</tr>
-
<?php $i++;
-
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
-
</table>
-
-
//////////////And heres the Nav Bar...:
-
-
<table border="0" width="50%" align="center">
-
<tr>
-
<td width="23%" align="center">
-
<?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
-
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border=0></a>
-
<?php } // Show if not first page ?>
-
</td>
-
<td width="31%" align="center">
-
<?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
-
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border=0></a>
-
<?php } // Show if not first page ?>
-
</td>
-
<td width="23%" align="center">
-
<?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
-
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>"><img src="Next.gif" border=0></a>
-
<?php } // Show if not last page ?>
-
</td>
-
<td width="23%" align="center">
-
<?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
-
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border=0></a>
-
<?php } // Show if not last page ?>
-
</td>
-
</tr>
-
</table>
-
Thanks for your help on this..
Thanks for your help pbmods. When I tried the $offset it seems to miss the 1st place entry.
I'm assuming that the $offset + 1; goes at the start of the loop in place of $i=1;
Thanks again
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michel |
last post by:
Hi all,
This is my first post, so I am very new at this. I am trying to use
page-number-citation twice in my code, but the second time it just
shows '0'. The output is in pdf format and I am...
|
by: b0yce |
last post by:
Hi Group,
I think I have found a problem with the <xsl:element> when being
transformed by the .NET xmlTransform class. When using XmlSpy for
development and debugging, the <xsl:number>...
|
by: Shane |
last post by:
I wonder if someone has any ideas about the following.
I am currently producing some reports for a manufacturing company who work
with metal.
A finished part can contain multiple sub-parts to...
|
by: Megan |
last post by:
Hi Everybody-
I know that this is a really, really long post, but I wanted to try to
give you as much background as possible.
So here's a quick overview of the issues I'm asking for help with:...
|
by: Ron |
last post by:
Hi all
I'm deciding whether to use the PK also as an account number, invoice
number, transaction number, etc that the user will see for the respective
files. I understand that sometimes a...
|
by: Jean-François Michaud |
last post by:
Hello all,
I need to generate (SHEET X of Y) in titles for figures contained in a
section (I already generate page A of B at the bottom right of every
page in the document).
Is there a way...
|
by: MN |
last post by:
Hello,
I have a customer table and another table that I need to prepopulate
with special customer IDs, unique and not sequential. Is there a way to
configure Access to assign the customer ID to...
|
by: King |
last post by:
Hi
I have following MS Acess query
Here is the query
ID Name Prgm ID Client ID Date Start Time End
Time Minutes
C4 Trisha TIP DEK0703 7 /7 /2006...
|
by: Scotter |
last post by:
Ok, I have 3 tables, one with a customer ID(PK) number and info about the customer(customer table). Another table with an order number(PK), with payment info and such, bieng linked by the customer...
|
by: Elfae |
last post by:
I have searched high and low for a sample for this, and I just can't
find any. Sorry for the length!
Background Information
The issue revolves around setting up a system-generated increase in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |