adam291086 Posted January 22, 2008 Share Posted January 22, 2008 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 />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87192-solved-reading-a-csv-file/ Share on other sites More sharing options...
rajivgonsalves Posted January 22, 2008 Share Posted January 22, 2008 this echo "<td>$newdata</td>"; should be echo (trim($newdata) != "") ? "<td>$newdata</td>" : "<td> </td>"; Quote Link to comment https://forums.phpfreaks.com/topic/87192-solved-reading-a-csv-file/#findComment-445991 Share on other sites More sharing options...
adam291086 Posted January 22, 2008 Author Share Posted January 22, 2008 Thanks, it works like a dream. I was creating some if statement.HA Quote Link to comment https://forums.phpfreaks.com/topic/87192-solved-reading-a-csv-file/#findComment-445997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.