I am sorry I thought you wanted the order of the data in each row changed not the order in which each row is displayed.
<?php
function createRandomPassword() {
$chars = "abcdefghijkmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 29) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp; $i++;}
return $pass;
}
}
$password = createRandomPassword();
$flashData = $_POST["inputData"];
$flashTime = $_POST["Timenow"];
$flashfile = $_POST["passy"];
$route = "../results/";
$ext = ".html";
if ($flashfile=="") {
$myTextFileHandler = @fopen("$route$password$ext","a+");
$flashfile = $password;
$unique = $password;
$txtfile = @file("$route$flashfile$ext");
}
else if ($flashfile!="") {
$myTextFileHandler = @fopen("$route$flashfile$ext","a+");
$flashfile = $flashfile;$unique=$flashfile;
$txtfile = @file("$route$flashfile$ext");
}
else if (file_exists("$route$flashfile$ext")) {
$myTextFileHandler = @fopen("$route$flashfile$ext","a+");
$flashfile = $flashfile;$unique=$flashfile;
$txtfile = @file("$route$flashfile$ext");
}
else if (!file_exists("$route$flashfile$ext")) {
$myTextFileHandler = @fopen("$route$password$ext","a+");
$flashfile = $password;
$unique = $password;
$txtfile = @file("$route$flashfile$ext");
}
if($myTextFileHandler) {
foreach($txtfile as $count => $member) {
$gotoLastByteOfTxTFile = @fseek($myTextFileHandler,0,SEEK_END);
$count = $count+ 1;
$T1 = "<title>" . $flashfile . $ext . "</title><body bgcolor='#333333'><Table cellspacing='0' cellpadding='0' width='100'><tr><td height='3'></td></tr></table>";
$T2 = "<table cellspacing='0' cellpadding='0' style='border:1px solid #BBD8FB;font-family:Arial,Helvetica,sans-serif;font size:13px;' align='center'><tr><td width='40' style='padding-left:10px;' bgcolor='#ffffff'>$count.</td>";
$T3 = "<td bgcolor='#D2E5FC' width='460' style='border-left:1px solid #BBD8FB;padding-left:10px;'>Lottery Numbers Generated : " . $flashTime . "</td>";
$T4 = "<td bgcolor='#F3F7FD' width='200' style='border-left:1px solid #BBD8FB;padding-left:10px;'><font color='#0000FF'>" . $flashData . "</font></td></tr><table></body>";
$T5 = "\n" . $T1 . $T2 . $T3 . $T4;
$text = @fwrite ($myTextFileHandler, $T5);
if($text) {
$writeStatus = "Your numbers were successfully saved and can be viewed at<br><img vspace='0' hspace='0' align='' src ='data/file.png'> <a href='results/" . $flashfile . $ext . "' target='_blank'>" . $flashfile . $ext . "</a>";
$uniqueStatus = $unique;
$secret = $unique;
print("&writeStatus=$writeStatus&uniqueStatus=$uniqueStatus&secret=<font color='#000'>$uniqueStatus</font>");
}
else {
$writeStatus = "Your numbers were not saved.";
print("$writeStatus=$writeStatus");
}
@fclose($myTextFileHandler);
}
else{
print("Failed to open file.");
}
}
?>
To help I had to make your code readable. In editing it I found a lot of problems.
First your "print" functions are the strangest things I have ever seen. Take this else statement
else {
$writeStatus = "Your numbers were not saved.";
print("$writeStatus=$writeStatus");
}
why not just echo the text
else {
echo "Your numbers were not saved.";
}
would that not do the same thing?
Third, the "createRandomPassword" function I beieve it should have a closing bracket "}" just before the "$password" variable.
Fourth, in the "createRandomPassword" the "srand()" is unused as it is not assigned to any variable.
Fifth, I see you have all your data stored in ".html" files. I guess in a worst case scenario one could choose to use a ".txt" file for data storage but an HTML file seems a bit odd. But the real question is why aren't you using a database, this would be much easier I would think.
Sixth, not to get to particular but how you use variables in conjunction with text and other variable is a bit off.
$txtfile = @file("$route$flashfile$ext");
this would be technically the better way, and more readable
$txtfile = @file($route . $flashfile . $ext);
Not that your way won't work just there are times it may cause you a headache. As well you can see what I did to the $T1 - $T4 variables when variables were in there strings.
And lastly the "foreach" loop had no opening bracket "{" which I then also found there was no closing bracket "}". The "foreach" is a critical part of solving this problem. I took a guess on were they go but I could be wrong. Those brackets could make or brake this hence you will need to make sure they are in the right place.
Now to your solution. As I said before a database would be 1000 times easier. But if you wish to stick with text files you will need to extract the data from each file and place it in an array and then each array will need to be in an array and then you can sort by the dates and then use a foreach or while loop to display the data in the sorted order.
At this point I have tried to figure out how to write that code out for you but I have no idea what is in those files or how they are structured. And really I have almost 0 experience in working with data stored in files. So hopefully my making the code readable and cleaning it up some will help someone else in these forums give you some further direction.