I have a csv file that is converted to an html table by php (with help from Joby Joseph here): Dynamically display a CSV file as an HTML table on a web page
However, I would like to put the data into separate tables and container divs based on the values in the first two columns. So if this is my csv data:
League,Team,Date,Opponent,Result
american,MIN,May 3,UTA,W
american,MIN,May 4,SEA,L
american,SAC,May 3,DAL,L
american,SAC,May 4,TOR,W
national,NYN,May 5,BAL,L
national,NYN,May 7,MIA,W
national,DET,May 6,DEN,L
national,DET,May 7,POR,L
There would be four tables created (MIN, SAC, NYN, and DET), and they would be put into container divs that I have already created, "american-container" for the first two and "national-container" for the second two. Ideally, each table would have two header rows--the team name and the column labels--and the date/opponent/result data. Following is Joby's solution that puts the csv into one table:
function jj_readcsv($filename, $header=false) {
$handle = fopen($filename, "r");
echo '<table>';
//display header row if true
if ($header) {
$csvcontents = fgetcsv($handle);
echo '<tr>';
foreach ($csvcontents as $headercolumn) {
echo "<th>$headercolumn</th>";
}
echo '</tr>';
}
// displaying contents
while ($csvcontents = fgetcsv($handle)) {
echo '<tr>';
foreach ($csvcontents as $column) {
echo "<td>$column</td>";
}
echo '</tr>';
}
echo '</table>';
fclose($handle);
}
jj_readcsv('test.csv',true);
Thanks for any help.