close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Ranked list

Thread began 8/11/2021 7:11 am by birdscreen398247 | Last modified 8/12/2021 9:59 am by Ray Borduin | 402 views | 4 replies |

birdscreen398247

Ranked list

I would like to automatically rank the records in a query of numbers, so that the highest one is 1, the next lower one is 2, etc.

However, where there are two numbers the same, they should have the same rank and the next entry would then compensate for all of those records with the same rank.

Ie. In the sample file attached, it would look like this"

Rank Quantity
1 391
2 390
2 390
4 385 (this record is #4 because there are 3 records above it.)
etc.

Is there an easy way to do this?

Sign in to reply to this post

Ray BorduinWebAssist

Something like this would probably do it:

php:
<?php

$rank 
0;
$lastVal = -1;
$skipped 0;
?>
<?php
$wa_startindex 
0;
while(!
$rsLists->atEnd()) {
  
$wa_startindex $rsLists->Index;
    if (
$lastVal != $rsLists->getColumnVal("Quantity")) {
        
$lastVal $rsLists->getColumnVal("Quantity");
        
$rank += $skipped 1;
                
$skipped 0;
    } else {
        
$skipped++;
    }
?>
  <tr>
    <td><?php echo($rank); ?></td>
    <td><?php echo($rsLists->getColumnVal("Quantity")); ?></td>
    <td><?php echo($rsLists->getColumnVal("FullName")); ?></td>
  </tr>
  <?php
  $rsLists
->moveNext();
}
$rsLists->moveFirst(); //return RS to first record
unset($wa_startindex);
unset(
$wa_repeatcount);
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

birdscreen398247

Close, but no cigar...

The results are

1 391 Barbara Haas
2 390 Franklin Haas
2 390 Devich Farbotnik
4 385 Dave DeReamus (ok to here, but then...)
6 383 Peter Robinson (should be 5)
8 379 Eric Witmer (should be 6) etc.
10 375 Tom Garner
12 374 Ken Lebo

For some reason it is adding an extra rank.

Sign in to reply to this post

Ray BorduinWebAssist

I forgot to reset the skipped to zero once it was accounted for. I updated the code.

Sign in to reply to this post
Did this help? Tips are appreciated...

birdscreen398247

That's a winner!

Thanks

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...