I'm trying to create a scoring system using flat file (I know, I'd prefer to use mysql too). I have managed to create enough so that the variables are pulled out of the game (username and score) and put into said text file. I can also output this text file in a formatted table. However i cannot get the scores to sort in any order - ideally i want descending. After searching the web the best i could find is in the attached code however this doesn't seem to actually do anything at the moment. I know its probably a stupid mistake somewhere but i could do with a fresh pair of eyes to look over it. Many Thanks, Harry
<?php
echo '<table width="5%" border="5"><tr><th>Your Score</th><th>Your Name</th></tr>';
echo '<tr><td>'.$_POST["m_score"].'</td><td>'.$_POST["name"].'</td></tr>';
echo '</table>';
echo "<br />";
$data=$_POST["m_score"].",".$_POST["name"].",";
$filename = "./highscores.txt";
$handle = fopen($filename, "a");
if (!$handle)
{
print "There were problems opening the file";
exit();
}
fwrite($handle, $data);
fclose($handle);
$handle = fopen($filename, "r");
$datain = fread($handle, filesize($filename));
$value = explode(",",$datain);
$row = floor(count($value)/2);
$count = 0;
$filename = file("./highscores.txt");
sort($filename);
file_put_contents("./highscores.txt", implode($filename));
echo '<table width="5%" border="1"><tr><th>Top Scores</th><th>Top Users</th></tr>';
for ($i=0;$i<$row;$i++)
{
echo '<tr>';
for($x=0;$x<2;$x++){
echo "<td>$value[$count]</td>";
$count++;
}
echo "</tr>";
}
echo '</table>';
fclose($handle);
?>