Focusing just on the array sort I mentioned above...here is the code I have for the page so far, I'm trying to use usort, but the sort isn't working. I'm not even sure how it's supposed to work since all the records from the text file are never in the same array together....there's a loop that makes a one-dimensional array for each record every time through, so I'm not sure how I'm supposed to sort those records when they're never really in the same array together. Again, what I want to happen is, when the contents of the array are all outputted into the dynamically created table, I want them to be sorted by the date in which they were written to the text file(the date is in [0] of the array) from most recent to least recent. I know that what I have here for the sort shouldn't work, but I just don't know what to do to make it work.
<?php
//create short variable name
$DOCUMENT_ROOT = dirname($SERVER['PATH_TRANSLATED']);
?>
<html>
<head>
<title>Bob's Auto Parts - Feedback Results</title>
</head>
<body bgcolor="#00ffff">
<h1>Bob's Auto Parts</h1>
<h2>Feedback Results</h2>
<?php
$ftype = $POST['ftype'];
//Read in the entire file.
//Each order becomes an element in the array
$orders= file("$DOCUMENT_ROOT/comments.txt");
// count the number of orders in the array
$number_of_orders = count($orders);
if ($number_of_orders == 0)
{
echo '<p><strong>No feedback available.
Please try again later.</strong></p>';
}
echo "<table border=0 bgcolor=#00ff00 cellspacing=10>\n";
echo '<tr><th bgcolor="#00ff00">Date Of Comment</th>
<th bgcolor="#00ff00">Name</th>
<th bgcolor="#00ff00">E-Mail Address</th>
<th bgcolor="#00ff00">Feedback Type</th>
<th bgcolor="#00ff00">Comments</th>
<tr>';
$count = 0;
function DateCmp($a, $b)
{
return ($a[1] < $b[1]) ? -1 : 0;
}
for ($i=0; $i<$number_of_orders; $i++)
{
//split up each line
$line = explode( "\t", $orders[$i] );
//filter out feedbacktype
usort($line, 'DateCmp');
$tempStr = trim($line[3]);
$pos = "POSITIVES";
if (strcmp($tempStr,$ftype) == 0)
// output each order
{
echo "<tr><td>$line[0]</td>
<td align='right'>$line[1]</td>
<td align='center'>$line[2]</td>
<td align='center'>$line[3]</td>
<td align='right'>$line[4]</td>
</tr>";
$count = $count + 1;
}
}
if ($count==0)
echo("No $ftype Comments Found");
echo '</table>';
?>
</body>
</html>