Need help sorting highscore - rsort()

This is a discussion on "Need help sorting highscore - rsort()" within the PHP Forum section. This forum, and the thread "Need help sorting highscore - rsort() are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 7th, 2007, 04:22
New Member
Join Date: Apr 2007
Location: USA
Age: 37
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Need help sorting highscore - rsort()

Hi all you beautiful people

I'm making a Flashgame with a php highscore.
In my game I have a timer and I want the highscore to show me the lowest time.
But the code is created to show the best score.
I think I have to do something with the "rsort" or something.

Can anybody help me with this?

It works as it is, but the highest time is sortet to the top not the bottom.

If you help me I will include your name in the credits of the game.

http://www.mofle.net/moflegame2/

Start the game and click on the button named "Highscore" to test the Highscore.

The game is far from be finished...


Code: Select all
<?php

    $winscore = (int)$winscore;

    // Create a Blank File if it doesn't already exist
    if (!file_exists($filename))
    {
        $file=fopen($filename, "w");
        fclose ($file);
    }

    // Read the file in
    $oscores = file ($filename);
    $numreadin = count($oscores);

    // Break out the data into a new 2-d array called $tscores
    for ($i = 0; $i < $numreadin; $i++)
    {
        $g = unserialize($oscores[$i]);
        $tscores[$i][0] = $g[0];
        $tscores[$i][1] = $g[1];
    }

    // Fill in any missing data with none/0
    for ($i = $numreadin; $i < $scoresize; $i++)
    {
        $tscores[$i][0] = 0;
        $tscores[$i][1] = "none";
    }

    // Process the actions    

    // Insert a score/name
    if ($action == "INSERT")
    {

        // Add name to end of list, and sort
        $tscores[$scoresize + 1][0] = $winscore;
        $tscores[$scoresize + 1][1] = $winname;
        rsort ($tscores);

        $file=fopen($filename, "w");

        // Write them out
        for ($i = 0; $i < $scoresize; $i++)
        {
            $st = serialize($tscores[$i]) . "\n";
            fputs($file, $st);
        }

        fclose($file);
    }

    // Clear the list    
    if ($action == "CLEAR")
    {

        $k[0] = 0;
        $k[1] = "none";
        $ser = serialize($k);

        $file=fopen($filename, "w");

        for ($i = 0; $i < $scoresize; $i++)
        {
            $st = $ser . "\n";
            fputs($file, $st);
        }

        fclose($file);
    }

    // Process the OUTPUT options
    if ($viewtype == "HTML")
    {
      // HTML PAGE CREATED HERE
      ?>


        <table cellpadding=2 cellspacing=2 border=0 width="152">
        <tr align=center> 
        <th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">#</font></th>
        <th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Name</font></th>
        <th bgcolor="#000033"><font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Score</font></th>
        </tr>

         <?
    
        for ($i = 0; $i < $scoresize; $i++)
        {
            echo ("<tr bgcolor='#666666' align='center'><td><font size='2' face='Arial, Helvetica, sans-serif'>");
            echo ($i + 1);
            echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
            echo ($tscores[$i][1]);
            echo ("</font></td><td><font size='2' face='Arial, Helvetica, sans-serif'>");
            echo ($tscores[$i][0]);
            echo ("</font></td></tr>");
        }

        ?>
        </table>
      <?

    }

    // FLASH DATA CREATED HERE
    if ($viewtype == "FLASH")
    {
        for ($i = 0; $i < $scoresize; $i++)
        {
            echo ("NAME" . $i . "=");
            echo ($tscores[$i][1]);
            echo ("&SCORE" . $i . "=");
            echo ($tscores[$i][0]);
            echo ("&");
        }
    }

?>
Reply With Quote

  #2 (permalink)  
Old Apr 7th, 2007, 13:29
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need help sorting highscore - rsort()

Yes, changing rsort() to sort() will change the list from descending (highest first) to ascending (lowest first).
Reply With Quote
  #3 (permalink)  
Old Apr 8th, 2007, 09:41
SuperMember

SuperMember
Join Date: May 2006
Location: North West, UK
Age: 21
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need help sorting highscore - rsort()

I'm loving the game. I don't know anything about php though, sorry.

Let us know when it's all done. The little green dude is cool.

Pete.
Reply With Quote
Reply

Tags
flash, game, help, highscore, php, rsort

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help sorting an array djeyewater PHP Forum 6 Apr 18th, 2008 15:16
[SOLVED] Array sorting welshstew Classic ASP 6 Nov 28th, 2007 16:45
[SOLVED] PHP Sorting Stuart PHP Forum 10 Oct 20th, 2007 00:46
Sorting a PHP array fallen_angel PHP Forum 3 Apr 20th, 2007 22:18
2 minor problems need sorting AdRock Web Page Design 2 Mar 26th, 2007 21:12


All times are GMT. The time now is 07:12.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43