husslela03 Posted October 27, 2009 Share Posted October 27, 2009 I have this code below that displays information from a flat text file in rows and columns using fgetcsv(). I would like to know how to be able to add an extra column to the end with a heading and be able to calculate information for that row and display it in that column. I would also like to know how to write a new column to the flat text file. $row=1; $handle= fopen($full_file,'r'); $heading=True; echo '<table>'; while (($data=fgetcsv($handle,1024,":")) !==FALSE) { echo '<tr>'; foreach($data as $cell) { echo ($heading) ? '<th>' : '<td width=10>'; echo $cell; echo ($heading) ? '</th>' : '</td>'; } if ($row==1) { $heading=False; } $row++; echo '</tr>'; } echo '</table>'; fclose($handle); Link to comment https://forums.phpfreaks.com/topic/179209-need-to-be-able-to-write-a-column-to-a-flat-text-file-and-also-to-display/ Share on other sites More sharing options...
cags Posted October 27, 2009 Share Posted October 27, 2009 Sounds like you want something like... echo '<table>'; // output header data $data = fgetcsv($handle,1024,":"); echo '<tr>'; foreach($data as $cell) { echo '<th>' . $cell . '</td>'; } // output extra column header echo '<th>Something</th>'; echo '</tr>'; // loop through data while (($data=fgetcsv($handle,1024,":")) !==FALSE) { echo '<tr>'; foreach($data as $cell) { echo '<td width="10">' . $cell . '</td>'; } // output extra column here echo '<th>Something</th>'; echo '</tr>'; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/179209-need-to-be-able-to-write-a-column-to-a-flat-text-file-and-also-to-display/#findComment-945533 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.