Results 1 to 3 of 3

Thread: Rang numbers

  1. #1
    Join Date
    Feb 2005
    Posts
    5

    Unanswered: Rang numbers

    Hi,

    I am making a programme where at the end a total list is coming from out of a database order by the total scores, the highest first etc...

    Every row gets a rang number in front of this line, but now I would like that if two or more rows have the same total score, the rang number isn't visible in front of the second row with that same total score and that the next country with a lower score get the right rang number.

    example:

    1. Norway 120 points
    2. Zweden 100 points
    Danmark 100 points
    4. Finland 80 points

    Till now I have the following part of the script, but hopefully someone can tell me what I have to do to get this done. The total scores are based on $row[7] and are taken out of a database.

    The script is:

    $query = "SELECT * FROM result order by Total desc";
    $result = @mysql_query ($query); // Run the query.

    while ( $row = mysql_fetch_array($result) )
    {
    echo '<table border=0 width=800>';
    echo "<tr>";
    $rang++;
    echo "<td width=20><b>$rang</b></td>";
    echo "<td width=180><b>$row[1]</b></td>";
    echo "<td width=100><center><b>$row[2]</b></td>";
    echo "<td width=100><center><b>$row[3]</b></td>";
    echo "<td width=100><center><b>$row[4]</b></td>";
    echo "<td width=100><center><b>$row[5]</b></td>";
    echo "<td width=100><center><b>$row[6]</b></td>";
    echo "<td width=100><center><b>$row[7]</b></td>";
    echo "</tr>";
    echo "</table>";
    }

  2. #2
    Join Date
    Dec 2004
    Posts
    27
    instead of this try adding to it, something like this,

    PHP Code:
    // since we have no way of telling what var is holding the 
    // "Total Score" i'm going to assume that its $row[1].

    $query "SELECT * FROM result order by Total desc";
    $result = @mysql_query ($query); // Run the query.

    while ( $row mysql_fetch_array($result) )
    {

    if(
    $row[1] != $score) {
    $display_rang $rang++;
    }else{
    $display_rang "";
    }

    echo 
    '<table border=0 width=800>';
    echo 
    "<tr>";

    echo 
    "<td width=20><b>$display_rang</b></td>";
    echo 
    "<td width=180><b>$row[1]</b></td>";
    echo 
    "<td width=100><center><b>$row[2]</b></td>";
    echo 
    "<td width=100><center><b>$row[3]</b></td>";
    echo 
    "<td width=100><center><b>$row[4]</b></td>";
    echo 
    "<td width=100><center><b>$row[5]</b></td>";
    echo 
    "<td width=100><center><b>$row[6]</b></td>";
    echo 
    "<td width=100><center><b>$row[7]</b></td>";
    echo 
    "</tr>";
    echo 
    "</table>";

    $score $row[1];

    try that out and let me know if it works. I didn't test this but it should work in theory.

    hope that helps!

  3. #3
    Join Date
    Feb 2005
    Posts
    5
    Yes...great...it works and sorry I forgot to mention the totals were in the last row, but I changed them both in $row[7] and everything works fine.

    Thank you and who knows talk to you another time

    Osloman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •