Jump to content

[SOLVED] Reading a CSV File


adam291086

Recommended Posts

I have a script that opens my CSV file and prints the information out onto the screen. Thanks to you guys i got that working in the first place.

 

The problem is that when a column is not filled in, the empty feild is displayed without a border and therefore looks a bit odd. You can see whats happening http://ryedalerumble.co.uk/riders.php here. Here is the code, any suggestions are appreciated.

 

<?php


$filename = "../current/htdocs/excel/CSV/riders.csv";
$id = fopen($filename, "r");

while ($data = fgetcsv($id, filesize($filename),";"))
$table[] = $data;

fclose($id);

echo "<table width=\"100%\" border=\"1\" align=\"left\">\n";

foreach($table as $row)
{
echo "<tr>";
 foreach($row as $data) 
 { 
 $data  = split (",", $data);

  foreach ($data as $newdata)
  {
  echo "<td>$newdata</td>"; 
  }
 }
echo "</tr>\n";
}
echo "</table>\n";
echo "<br />";
?>    

Link to comment
https://forums.phpfreaks.com/topic/87192-solved-reading-a-csv-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.