about2flip Posted December 21, 2008 Share Posted December 21, 2008 Hi: I am a php newbie, and I am trying to display data put into a txt or csv file into tables. I am using this code: <?php $filename = "data.txt"; $id = fopen($filename, "r"); while ($data = fgetcsv($id, filesize($filename),";")) $table[] = $data; fclose($id); echo '<table cols="2" border="0" cellpadding="0" cellspacing="0" align="center" width="100%">'; foreach($table as $row) { echo "<tr>"; foreach($row as $data) echo "<td>$data</td>\n"; echo "</tr>\n"; } echo "</table>\n" ?> It displays correctly, but I need the food in one column and the price per in another or if there is some way I can tab to make it look neater. Shrimp Salad $7.25 Per Person Albacore Tuna Salad $4.00 Per Person Hand Picked Chicken Salad $5.00 Per Person Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/ Share on other sites More sharing options...
blueman378 Posted December 21, 2008 Share Posted December 21, 2008 use \t its a tab break Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/#findComment-721000 Share on other sites More sharing options...
about2flip Posted December 21, 2008 Author Share Posted December 21, 2008 Thanks for replying, but where do i place \t. Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/#findComment-721005 Share on other sites More sharing options...
blueman378 Posted December 21, 2008 Share Posted December 21, 2008 where ever you want a tab... Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/#findComment-721010 Share on other sites More sharing options...
about2flip Posted December 21, 2008 Author Share Posted December 21, 2008 This is the result I get from the txt file Shrimp Salad $7.25 Per Person Albacore Tuna Salad $4.00 Per Person Hand Picked Chicken Salad $5.00 Per Person I want to tab between the name of the sandwich and price This is the line that prints the code, so where would i put \t to push the price over more to the right? echo "<td>$data</td>\n"; Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/#findComment-721021 Share on other sites More sharing options...
blueman378 Posted December 21, 2008 Share Posted December 21, 2008 ah right, sorry only jsut read properly, looking at that your going to have to have some character in between them and them explode/implode? them into an array, then process that. Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/#findComment-721022 Share on other sites More sharing options...
about2flip Posted December 22, 2008 Author Share Posted December 22, 2008 Hate to be a pain... but how do i do that. I am php newbie. Thanks Again. Link to comment https://forums.phpfreaks.com/topic/137913-need-help-displaying-txt-or-csv-into-tables/#findComment-721044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.