Hi, I'm having a problem with sorting rows from a csv file, where I would like to have the latest line of data appended to the csv file to be displayed as the topmost line in the HTML page. How do I do that with the fgetcsv function?
Here's my current code :
$row =0;
$tmpdata="";
$handle = @fopen("course_db.csv", "rb") or die("Couldn't open file");
echo "<TABLE WIDTH='1195' BORDER='1' BORDERCOLOR='#CCCCCC' CELLSPACING='0' CELLPADDING='3' >";
while ($data = fgetcsv ($handle, 1000)) {
$num = count ($data);
$row++;
echo "<TR VALIGN='TOP'><TD ALIGN='LEFT' WIDTH='25'>" . $row . "</TD>";
for ($c=0; $c <$num; $c++) {
$tmpdata = $data[$c];
if(($c == 0) || ($c == 11)) {
$tmpdata = preg_replace("/\&\&/", "<br>", $tmpdata);
} echo "<TD ALIGN='LEFT' WIDTH='90'>";
echo $tmpdata ."</TD>";
}echo "</TR>";
}echo "</TABLE>";
fclose ($handle);