Hi, I'm new to php and need help. Please find the code below. It is supposed to retrieve data from my csv file and sort it by last name; placing it in a sorted table. I'm getting errors and don't know how to fix it. I'm also running out of time to get it done. Please help! :eek:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Telephone Directory Sorted Array</title>
</head>
<body>
<?php
// Opens and Gets the data found within the CSV file called data_file.csv
$datafile = "data_file.csv";
if (is_readable($datafile)){
$data = file_get_contents("data_file.csv");
explode(", ", $data);
}
// Associative Array
$data["lastname"];
$data["firstname"];
$data["areacode"];
$data["phonenum"];
// Table header
echo "<table border='1'>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Phone Number</th>";
echo "</tr>";
// Sort the associate array by key
ksort($lastname);
//Print out the sorted array
foreach($data as $lastname => $phonenum) {
echo "<tr>";
echo "<td>$lastname, $firstname</td>";
echo "<td>$areacode-$phonenum</td><br>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>