I've made a very simple agenda system, with the following code:
<?
$fcontents = file ('agenda.txt');
// loop waarin alle gegevens worden ingelezen uit agenda.txt
while (list ($line_num, $line) = each ($fcontents)) {
//maken van een array in variabele $agenda
//$agenda[0] is de datum, $agenda[1] de titel en $agenda[2] de link
$agenda = explode(",",$line);
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
// alleen items van vandaag en later weergeven
if ($agenda[0] >= $today) {
if (!($line_num % 2)) {
$bgcolor = "FF00FF";
}
else {
$bgcolor = "00FF00";
}
echo "<tr><td bgcolor=#".$bgcolor.">";
echo "".NLDate($agenda[0])."<br>";
echo "<a href='".$PHP_SELF."?file=".trim($agenda[2])."'>".$agenda[1]."</a>\n";
echo "<br>";
echo "</td></tr>";
}
?>
As you see, this script opens the file agenda.txt and reads its contents. I've also created a web interface to add new appointments to the file agenda.txt
No problem so far. But, I don't want to be forced to enter the dates in the order as they occur in order to have the events sorted from first to last.
So, what do I need to change to have an output with sorted events, from first to last?
Thanks in advance.
P.s. I'm new the PHP and created this with help of the documentation at php.net. I found the sort() function, but reading the documentary made me think this wouldn't work in this case. Please advice.