Sorry if this is a bit long, but I want to be as detailed as possible. Basically, I'm trying to create a multi-column table from a CSV file using PHP. I would like the table cells to list vertically. For example, if I have a CSV file with the names:
bill
mike
sarah
steve
kim
dave
Assuming I need 2 columns, I would like the table to list vertically like this:
bill steve
mike kim
sarah dave
I DO NOT want the table to list horizontally, like this:
bill mike
sarah steve
kim dave
I have used the following code to make a one column table from a CSV file of player names, team names - and I also passed in a team position attribute. I would like to be able to split the column vertically into 3 columns. Here is the code:
<?PHP
$file_handle = fopen("CSV Team Example.csv", "r");
echo "<table border = '0' cellspacing='1' cellpadding='3'>\n";
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle);
echo "<tr>\n<td width = '200' position = '" . $line_of_text[2] . "'>". $line_of_text[0]. " <br> " . $line_of_text[1] . "</td>\n</tr>\n";
}
fclose($file_handle);
echo "</table>";
?>
Here is the CSV file I'm working from. Thank you very much in advance for your consideration.
CSV file:
Scott L. Aranda,Red Devils,Offense
Todd D. Smith,Blue Streaks,Offense
Edward M. Grass,Red Devils,Defense
Aaron G. Frantz,Blue Streaks,Defense
Ryan V. Turner,Red Devils,Offense
Belinda J. Bridges,Red Devils,Defense
Raymond P. Webb,Blue Streaks,Offense
Allison M. Elwell,Blue Streaks,Defense
Melinda B. Savino,Blue Streaks,Offense
Wendy R. Lane,Red Devils,Offense
Gordon Q. Farmer,Blue Streaks,Defense
William F. Lawrence,Red Devils,Offense
Christa L. Limones,Blue Streaks,Offense
Sandra C. Singleton,Red Devils,Offense
Keshia M. Garcia,Blue Streaks,Defense
Margaret A. Arnold,Red Devils,Defense
Paul S. Gonzalez,Blue Streaks,Offense
Mark V. Stocks,Red Devils,Defense
Elizabeth J. Quinn,Red Devils,Offense
Rusty M. Collette,Red Devils,Offense
Myra L. Armstrong,Blue Streaks,Defense
William B. Stewart,Blue Streaks,Defense
Erin J. Hoch,Red Devils,Defense
Robin S. Meredith,Blue Streaks,Offense
Sherie D. Lee,Red Devils,Offense
Michael A. Whitney,Blue Streaks,Defense
Louis R. Ochoa,Red Devils,Defense
Paul R. Garcia,Blue Streaks,Offense
Chester A. Bailey,Red Devils,Defense
Johnny B. Coover,Red Devils,Defense
Emily K. Wright,Red Devils,Offense
Perry D. Desmarais,Red Devils,Offense
Judie J. Burns,Blue Streaks,Defense
Martin L. Dunn,Blue Streaks,Defense
Stephanie C. Rose,Blue Streaks,Defense
Don T. Grimes,Blue Streaks,Offense
Robert C. Devito,Blue Streaks,Offense
Michael J. Taylor,Red Devils,Defense
Melissa D. Bush,Red Devils,Offense