473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Number each row in a table

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
Nov 27 '07 #1
6 4607
Lumpy
69
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...
Expand|Select|Wrap|Line Numbers
  1. $i = 1;
  2.  
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...
Expand|Select|Wrap|Line Numbers
  1. $i++;
  2.  
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!
Nov 27 '07 #2
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
Nov 27 '07 #3
Lumpy
69
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.
Nov 27 '07 #4
pbmods
5,821 Expert 4TB
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.
Nov 27 '07 #5
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:
Expand|Select|Wrap|Line Numbers
  1. <table width="30%"  border="0" cellspacing="0" cellpadding="0">
  2.     <tr>
  3.       <td>Rank</td>
  4.       <td>Score</td>
  5.       <td>Name</td>
  6.     </tr>
  7.     <?php 
  8.     $i=1;
  9.     do { ?>
  10.     <tr>
  11.       <td><? echo $i ?></td>
  12.       <td><?php echo $row_Recordset1['score']; ?></td>
  13.       <td><?php echo $row_Recordset1['name']; ?></td>
  14.     </tr>
  15.     <?php $i++;
  16.      } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  17.   </table>
  18.  
  19. //////////////And heres the Nav Bar...:
  20.  
  21. <table border="0" width="50%" align="center">
  22.       <tr>
  23.         <td width="23%" align="center">
  24.           <?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  25.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>"><img src="First.gif" border=0></a>
  26.           <?php } // Show if not first page ?>
  27.         </td>
  28.         <td width="31%" align="center">
  29.           <?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
  30.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>"><img src="Previous.gif" border=0></a>
  31.           <?php } // Show if not first page ?>
  32.         </td>
  33.         <td width="23%" align="center">
  34.           <?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  35.           <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>
  36.           <?php } // Show if not last page ?>
  37.         </td>
  38.         <td width="23%" align="center">
  39.           <?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
  40.           <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>"><img src="Last.gif" border=0></a>
  41.           <?php } // Show if not last page ?>
  42.         </td>
  43.       </tr>
  44.     </table>
  45.  
Thanks for your help on this..
Nov 27 '07 #6
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
Nov 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
3
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>...
5
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...
0
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:...
13
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...
0
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...
5
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...
8
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...
26
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.