A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Highscore in HTML

  1. #1
    Senior Member
    Join Date
    Jun 2004
    Location
    Estonia
    Posts
    116

    Highscore in HTML

    Hi,

    I have a highscore board in FLASH but is there a way to display it in HTML.

    Here's the php.
    PHP Code:
    <?php 
    /*
         // FLASH-HIGHSCORE by Daniel Lonn   http://www.webknecht.net
        // -------------------------------------------------------------------------------------
       //               let me know the changes if you modifie this script for
      //                   a better db-perfomance: webknecht@webknecht.net

    MYSQL: 2 tables needs to be created:

    CREATE TABLE `NBonline` (
      `IP` varchar(15) NOT NULL default '',
      `EXPIRE` int(10) unsigned default NULL,
      `NAME` varchar(20) NOT NULL default '',
      PRIMARY KEY  (`NAME`),
      KEY `IP` (`IP`)
    )

    CREATE TABLE `scoreNR2` (
      `IP` varchar(15) NOT NULL default '',
      `NAME` varchar(20) NOT NULL default '',
      `COUNTER` int(5) default NULL,
      `DATE` varchar(12) NOT NULL default '',
      PRIMARY KEY  (`NAME`),
      KEY `IP` (`IP`)
    )

    FLASH: you have to set dynamic textfields for every output-variable
           i.e. to display 10 highscore-rows:

                score0 ... score9
                name0 ... name9
                date0 ... date9

           and flash variables for name and scores for a new player
           you could send and load the highscore-values with:
           loadVariablesNum(highscore.php?"+PlayersNameVariable+"&"+_PlayersScoreVariable+"&test="+random(number),Level or mc to load in, "POST");
           i.e:
           loadVariablesNum(highscore.php?"+name+"&"+_scores+"&test="+random(99999),0, "POST");

      ------------------------ VARS TO EDIT BEGIN ----------------------------------------------*/

      
    $HOST "localhost";           // hostname
      
    $ID "gamers_score";                 // mySql-username
      
    $PW "password";                    // mySql-password
      
    $DB "gamers_scoreboard";               // mySql-db-name

      
    $time_range 1800;        // time-range in seconds to display online-users
      
    $display 100;            // number of highscore-rows to display in flash
      
    $score_min 1;          // '0' displays all scores || '1' displays only positive scores

    // ------------------------ VARS TO EDIT END ------------------------------------------------


      
    $tbl_NBonline "NBonline";
      
    $tbl_scoreNR2 "scoreNR2";
      
    $date date("d.m.Y");
      
    $remote_addr getenv("REMOTE_ADDR");

      if(
    $argv){
      
    $post_vars=implode($argv,'');
      
    $post_vars_array=explode("&",$post_vars);
      
    $name $post_vars_array[0];
      
    $score $post_vars_array[1];
      }

      
    $conn_id mysql_connect($HOST,$ID,$PW); 
      
    mysql_select_db($DB,$conn_id);

      
    // delete all old user-data from $tbl_NBonline
      
    mysql_query("DELETE FROM ".$tbl_NBonline." WHERE EXPIRE < ".time()."");

      if(
    $score_min 1){
      
    // delete all user-data from $tbl_scoreNR2 with negative scores
      
    mysql_query("DELETE FROM ".$tbl_scoreNR2." WHERE COUNTER <= 0;");
      }

      
    // user exist?
      
    $result3mysql_query("SELECT count(*) FROM ".$tbl_scoreNR2." where IP ='".$remote_addr."' and NAME = '".$name."'");

      if(
    mysql_result($result3,0) == 0){
      
    // user doesnt exist ==> new entry
      
    mysql_query("INSERT INTO ".$tbl_NBonline." (IP,NAME,EXPIRE) VALUES ('$remote_addr','$name','".(time()+$time_range)."');");
      
    mysql_query("INSERT INTO ".$tbl_scoreNR2." (IP,NAME,DATE,COUNTER) VALUES ('$remote_addr','$name','$date','$score');");
      } else {
      
    // user exist ==> update entry
      
    mysql_query("UPDATE ".$tbl_NBonline." SET EXPIRE = '".(time()+$time_range)."' WHERE IP ='".$remote_addr."'and NAME = '".$name."';");
      
    mysql_query("UPDATE ".$tbl_scoreNR2." SET  DATE = '".$date."',COUNTER = '".$score."' WHERE IP ='".$remote_addr."'and NAME = '".$name."';" );
      }

      
    // select all user-data from $tbl_scoreNR2 to display in the flashmovie
      
    $sql="select NAME,COUNTER,DATE from $tbl_scoreNR2 order by COUNTER desc";
      
    $result=mysql_db_query($DB,$sql,$conn_id);
      
    $count mysql_numrows($result);

      
    $i 0;
      while (
    $row mysql_fetch_array($result,MYSQL_ASSOC)) {
      if(
    $i $display && $i $count+1){
      
    str_replace"\n""",$row[NAME]);
      
    // flash output
      
    print "&name$i=".$row[NAME]."&score$i=".$row[COUNTER]."&date$i=".$row[DATE];
      
    $i++;
      }
      }

      
    // count of all Users online
      
    $online mysql_query("SELECT count(*) FROM ".$tbl_NBonline);
      
    $gesamt mysql_result($online,0);
      
    // flash output
      
    print "&online=".$gesamt;

    ?>
    I use this script to load:
    PHP Code:
    loadVariablesNum("highscore.php?"+name+"&"+score+"&test="+random(99999),0"GET"); 
    I hope someone can help me out.
    Thanks in advance
    Last edited by tonypa; 04-17-2006 at 02:54 AM. Reason: No cursing

  2. #2
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,471
    hate to be a nag but was that completly neccasary or cant you spell file right?

    I removed it - Tony
    Last edited by tonypa; 04-17-2006 at 02:55 AM.
    "I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."

  3. #3
    Senior Member
    Join Date
    Jun 2004
    Location
    Estonia
    Posts
    116
    It was not necessary, but it's not so big deal? Or is it...

  4. #4
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    To get the scores into HTML page instead of Flash use getURL and not loadVariablesNum. Then it will just output the data as plain text. To make it look prettier you can add print commands into php script to output actual html page.

  5. #5
    Senior Member
    Join Date
    Jun 2004
    Location
    Estonia
    Posts
    116
    Thanks for the answer.
    But still i'm not able to do that. Maybe because i don't no much PHP. And i don't understand the getURL, it is in Flash, how to affect HTML? (:

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center