Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a multi-column table from a CSV file using PHP
    text
    copied!<p>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:</p> <pre><code>bill mike sarah steve kim dave </code></pre> <p>Assuming I need 2 columns, I would like the table to list vertically like this:</p> <pre><code>bill steve mike kim sarah dave </code></pre> <p>I DO NOT want the table to list horizontally, like this:</p> <pre><code>bill mike sarah steve kim dave </code></pre> <p>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:</p> <pre><code>&lt;?PHP $file_handle = fopen("CSV Team Example.csv", "r"); echo "&lt;table border = '0' cellspacing='1' cellpadding='3'&gt;\n"; while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle); echo "&lt;tr&gt;\n&lt;td width = '200' position = '" . $line_of_text[2] . "'&gt;". $line_of_text[0]. " &lt;br&gt; &amp;nbsp;" . $line_of_text[1] . "&lt;/td&gt;\n&lt;/tr&gt;\n"; } fclose($file_handle); echo "&lt;/table&gt;"; ?&gt; </code></pre> <p>Here is the CSV file I'm working from. Thank you very much in advance for your consideration.</p> <p>CSV file:</p> <pre><code>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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload