BambooBasic takes this:-

'------------------------
'Project: HighscoreTable
'File: HighscoreTable.bam
'Company: Dabz
'Created: 11 Mar 2013

Include bam.string
Include bam.filesystem
Include bam.html
Include bam.http
Include bam.core

Local hiscorefile = CurrentDirectory() & "/hiscore.dat"

Local scores[]
Const HISCORE_AMOUNT = 5

Type TScores
    Field name
    Field score
EndType

Function FillUpNewFile()
    Global hiscorefile

    Local hifile = WriteFile(hiscorefile)
    WriteLine(hifile,"Dabz")
    WriteLine(hifile,"500")
    WriteLine(hifile,"Laura")
    WriteLine(hifile,"400")
    WriteLine(hifile,"Chris")
    WriteLine(hifile,"300")
    WriteLine(hifile,"Stella")
    WriteLine(hifile,"200")
    WriteLine(hifile,"Basil")
    WriteLine(hifile,"100")
    CloseFile(hifile)
EndFunction

'if hiscore file is not there, create it, then fill it up
If FileType(hiscorefile) == 0
    FillUpNewFile()
EndIf 

'Open the highscore file and read it in
Local filein = ReadFile(hiscorefile)

For Local loop = 0 To HISCORE_AMOUNT-1
    scores[loop] As TScores
    scores[loop]\name = ReadLine(filein)
    scores[loop]\score = (Integer)ReadLine(filein) 
Next

CloseFile(filein)

'Pick up any values from POST, and if needed, store
'in the highscore table, then, rejig it all!
If PostGlobal("new_name") && PostGlobal("new_score")
    Local newName = PostGlobal("new_name")
    Local newScore = (Integer) PostGlobal("new_score")

    'If the new score is higher then the last one on the table
    'process it, otherwise, nothing will change, so move on
    If newScore > scores[HISCORE_AMOUNT-1]\score
        Local placement = HISCORE_AMOUNT

        For Local checkScore = 0 To HISCORE_AMOUNT-1
            If newScore > scores[checkScore]\score
                placement = placement - 1
            EndIf 
        Next 

        For Local rejig = HISCORE_AMOUNT-1 To placement step -1
            If rejig != 0
                scores[rejig]\score = scores[rejig-1]\score
                scores[rejig]\name = scores[rejig-1]\name
            EndIf 
        Next

        scores[placement]\score = newScore
        scores[placement]\name = newName

        'All done, so lets save the hiscore table for next time
        Local fileout = WriteFile(hiscorefile)

        For Local loop = 0 To HISCORE_AMOUNT-1
             WriteLine(fileout,scores[loop]\name)
             WriteLine(fileout,scores[loop]\score)
        Next

        CloseFile(fileout)
    EndIf
EndIf

'Header
HTMLHeading(1) ; Print "Highscore example" ; HTMLEndHeading(1)

'Show highscores in a table
HTMLTable(1)
    HTMLTableHead()
        HTMLTableRow()
            HTMLTableHeaderCell()
                Print "Position" 
            HTMLEndTableHeaderCell()

            HTMLTableHeaderCell()
                Print "Name" 
            HTMLEndTableHeaderCell()

            HTMLTableHeaderCell()
                Print "Score" 
            HTMLEndTableHeaderCell()
        HTMLEndTableRow()
    HTMLEndTableHead()

    'Output highscore file into table
    HTMLTableBody()
        For Local outputScores = 0 To HISCORE_AMOUNT-1
            HTMLTableRow()
                HTMLTableCell()
                    Print (outputScores+1)
                HTMLEndTableCell()

                HTMLTableCell()
                    Print scores[outputScores]\name
                HTMLEndTableCell()

                HTMLTableCell()
                    Print scores[outputScores]\score
                HTMLEndTableCell()
            HTMLEndTableRow()
        Next
    HTMLEndTableBody()
HTMLEndTable()

'Show a form for new scores

HTMLHeading(3) ; Print "Enter new score:-" ; HTMLEndHeading(3)

HTMLForm("myform",ServerGlobal("PHP_SELF"))
    Print "Name: "
    HTMLInput("new_name","","text")
    Print "~b"
    Print "Score: "
    HTMLInput("new_score","","text")
    Print "~b"
    HTMLInput("","Submit","submit")
HTMLEndForm()

Then, converts it to this:-

<?php
include_once("bam/string.php");
include_once("bam/filesystem.php");
include_once("bam/html.php");
include_once("bam/http.php");
include_once("bam/core.php");
 $hiscorefile = bam_currentdirectory( ) . "/hiscore.dat";
 $scores = Array();
 define("HISCORE_AMOUNT",5 );
class tscores
{
    public  $name = NULL;
    public  $score = NULL;
}
function fillupnewfile ()
{
    global  $hiscorefile;
     $hifile = bam_writefile( $hiscorefile);
    bam_writeline( $hifile, "Dabz") ;
    bam_writeline( $hifile, "500") ;
    bam_writeline( $hifile, "Laura") ;
    bam_writeline( $hifile, "400") ;
    bam_writeline( $hifile, "Chris") ;
    bam_writeline( $hifile, "300") ;
    bam_writeline( $hifile, "Stella") ;
    bam_writeline( $hifile, "200") ;
    bam_writeline( $hifile, "Basil") ;
    bam_writeline( $hifile, "100") ;
    bam_closefile( $hifile) ;
}
if (bam_filetype( $hiscorefile) == 0 )
{
    fillupnewfile( ) ;
}
 $filein = bam_readfile( $hiscorefile);
for ($loop = 0 ;$loop <= HISCORE_AMOUNT- 1 ;$loop=$loop+1)
{
    $scores[ $loop]  = new  tscores;
    $scores[ $loop] ->name= bam_readline( $filein) ;
    $scores[ $loop] ->score= ( integer) bam_readline( $filein) ;
}
bam_closefile( $filein) ;
if (bam_postglobal( "new_name") && bam_postglobal( "new_score") )
{
     $newname = bam_postglobal( "new_name");
     $newscore = ( integer) bam_postglobal( "new_score");
    if ($newscore> $scores[ HISCORE_AMOUNT- 1 ] ->score)
    {
         $placement = HISCORE_AMOUNT;
        for ($checkscore = 0 ;$checkscore <= HISCORE_AMOUNT- 1 ;$checkscore=$checkscore+1)
        {
            if ($newscore> $scores[ $checkscore] ->score)
            {
                $placement= $placement- 1 ;
            }
        }
        for ($rejig = HISCORE_AMOUNT- 1 ;$rejig >= $placement;$rejig=$rejig- 1 )
        {
            if ($rejig!=0 )
            {
                $scores[ $rejig] ->score= $scores[ $rejig- 1 ] ->score;
                $scores[ $rejig] ->name= $scores[ $rejig- 1 ] ->name;
            }
        }
        $scores[ $placement] ->score= $newscore;
        $scores[ $placement] ->name= $newname;
         $fileout = bam_writefile( $hiscorefile);
        for ($loop = 0 ;$loop <= HISCORE_AMOUNT- 1 ;$loop=$loop+1)
        {
            bam_writeline( $fileout, $scores[ $loop] ->name) ;
            bam_writeline( $fileout, $scores[ $loop] ->score) ;
        }
        bam_closefile( $fileout) ;
    }
}
bam_htmlheading( 1 ) ;
echo "Highscore example";
bam_htmlendheading( 1 ) ;
bam_htmltable( 1 ) ;
    bam_htmltablehead( ) ;
        bam_htmltablerow( ) ;
            bam_htmltableheadercell( ) ;
                echo "Position";
            bam_htmlendtableheadercell( ) ;
            bam_htmltableheadercell( ) ;
                echo "Name";
            bam_htmlendtableheadercell( ) ;
            bam_htmltableheadercell( ) ;
                echo "Score";
            bam_htmlendtableheadercell( ) ;
        bam_htmlendtablerow( ) ;
    bam_htmlendtablehead( ) ;
    bam_htmltablebody( ) ;
        for ($outputscores = 0 ;$outputscores <= HISCORE_AMOUNT- 1 ;$outputscores=$outputscores+1)
        {
            bam_htmltablerow( ) ;
                bam_htmltablecell( ) ;
                    echo ( $outputscores+ 1 ) ;
                bam_htmlendtablecell( ) ;
                bam_htmltablecell( ) ;
                    echo $scores[ $outputscores] ->name;
                bam_htmlendtablecell( ) ;
                bam_htmltablecell( ) ;
                    echo $scores[ $outputscores] ->score;
                bam_htmlendtablecell( ) ;
            bam_htmlendtablerow( ) ;
        }
    bam_htmlendtablebody( ) ;
bam_htmlendtable( ) ;
bam_htmlheading( 3 ) ;
echo "Enter new score:-";
bam_htmlendheading( 3 ) ;
bam_htmlform( "myform", bam_serverglobal( "PHP_SELF") ) ;
    echo "Name: ";
    bam_htmlinput( "new_name", "", "text") ;
    echo "<br />";
    echo "Score: ";
    bam_htmlinput( "new_score", "", "text") ;
    echo "<br />";
    bam_htmlinput( "", "Submit", "submit") ;
bam_htmlendform( ) ;
?>

Which can be ran through your browser! :)

  • Michael