mrjiggyhill Posted June 8, 2009 Share Posted June 8, 2009 Hello all, Need a little help. I created a form. I have a php script that is taking the information from the form (user input) and placing it into a file. I also created a link to display this information from the file....and i'm having trouble with the coding to take the information from the file and to display it (preferably in a table - but I haven't gotten that far). <?php $Directory = fopen("directory.txt", "r"); $records[] = fgets($Directory); while (!feof($Directory)) { $row = explode(",",$records); foreach ($row as $field) { echo "$field"; } } fclose($Directory); ?> So i'm using the fopen to open the file then using the fgets to grab that information. Then doing a while loop (not end of file). Exploding the information in order to remove the commas - then trying to take the information from the array and displaying it record by record. Not sure where i'm going wrong..... Link to comment https://forums.phpfreaks.com/topic/161395-php-help-returning-information/ Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 Okey heres what you was doing wrong <?php $Directory = fopen("directory.txt", "r"); //$records[] = fgets($Directory); //this would read the line into an array while (!feof($Directory)) { $records = fgets($Directory); //read line $row = explode(",",$records); foreach ($row as $field) { echo "$field"; } } fclose($Directory); ?> untested code (for table) <?php $Directory = fopen("directory.txt", "r"); //$records[] = fgets($Directory); //this would read the line into an array echo "<table width=\"100%\" border=\"1\">"; while (!feof($Directory)) { $records = fgets($Directory); //read line #$row = explode(",",$records); //fancy trick /*i am replacing , with </td><td> and adding <td> at the start and </td> at the end*/ echo "<tr>"; echo "<td>".str_replace(",","</td><td>",$records)."</td>"; echo "</tr>"; } echo "</table>"; fclose($Directory); ?> Link to comment https://forums.phpfreaks.com/topic/161395-php-help-returning-information/#findComment-851798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.