ee Posted April 4, 2008 Share Posted April 4, 2008 If i have a text file with lines of code submitted: whilst i can break it line by line in a table...Is it possible to load each upload from the txt file into a new table???? e.g. <? $test = file("details.txt"); $number_of_adverts = count($test); if ($number_of_adverts == 0) { echo "<p>No Adverts currently</p>"; } echo "<table width = '40%' border=0 bgcolor = \"#000000\"> \n"; for ($i=0; $i<$number_of_adverts; $i++) $line = explode ( "\t", $test[$i] ); { echo "<tr><th align = 'left'>First Name</td><td align = 'left'>$line[0]</td></tr> <th align = 'left'>Surname</td><td>$line[1]</td></tr> <tr><td><br></td><td></td></tr> <th align = 'left'>Phone No</td><td>$line[2]</td></tr> <tr><td><br></td><td></td></tr> <th align = 'left'>Position Type</td> <td>$line[3]</td></tr> <tr><td><br></td><td></td></tr> <th align = 'left'>Details</td><td>$line[4] </td></tr> <tr><td><br></td><td></td></tr> <th align = 'left'>Education</td><td>$line[5]</td></tr> <tr><td><br></td><td></td></tr> <th align = 'left'>Time of Day to Contact</td><td>$line[6]</td> <tr><td><br></td><td></td></tr> <tr><td><br></td><td></td></tr> </tr>"; } echo "</table>"; ?> so, every line of record in the tetx file creates a new table down the screen??? Currently..this is only showing one of the lines from the text file???? Link to comment https://forums.phpfreaks.com/topic/99512-loading-array-from-txt-file-into-tables/ Share on other sites More sharing options...
gm04030276 Posted April 4, 2008 Share Posted April 4, 2008 try this... <?php $file = fopen("/path/to/file.txt"); while($line = fgets($file)){ $items = explode ( "\t", $line ); echo "<table> <tr> <th align = 'left'>First Name</th> #(watch your open/closing tags, i changed from /td to /th) <td align = 'left'>$items[0]</td> </tr> <th align = 'left'>Surname</th> #(watch your open/closing tags, i changed from /td to /th) <td>$line[1]</td> </tr> ...</table> } Link to comment https://forums.phpfreaks.com/topic/99512-loading-array-from-txt-file-into-tables/#findComment-509131 Share on other sites More sharing options...
Yesideez Posted April 4, 2008 Share Posted April 4, 2008 This is completely straight off the top of my head so I don't know if this will work but I hope it gives you the basic idea... $mydata=file("mydatafile.txt"); if (count($mydata)<1) { echo 'No data exists.'; } else { echo '<table width="40%" border="0" bgcolor="#000000">'; for ($i=0;$i<count($mydata);$i++) { $line=explode("\t",$mydata[$i]); echo '<tr><td>Forename</td><td>'.$line[0].'</td></tr>'; echo '<tr><td>Surname</td><td>'.$line[1].'</td></tr>'; echo '<tr><td>Phone</td><td>'.$line[2].'</td></tr>'; echo '<tr><td>Position</td><td>'.$line[3].'</td></tr>'; echo '<tr><td>Details</td><td>'.$line[4].'</td></tr>'; echo '<tr><td>Education</td><td>'.$line[5].'</td></tr>'; echo '<tr><td>Contact Time</td><td>'.$line[6].'</td></tr>'; } echo '</table>'; } Link to comment https://forums.phpfreaks.com/topic/99512-loading-array-from-txt-file-into-tables/#findComment-509148 Share on other sites More sharing options...
ee Posted April 8, 2008 Author Share Posted April 8, 2008 I still only get one line of records from text file in a table..it does not produce a second table for 2nd line of text file?? Link to comment https://forums.phpfreaks.com/topic/99512-loading-array-from-txt-file-into-tables/#findComment-511621 Share on other sites More sharing options...
ee Posted April 8, 2008 Author Share Posted April 8, 2008 I seem to have got it working with original code now! Thanks for help everyone! Link to comment https://forums.phpfreaks.com/topic/99512-loading-array-from-txt-file-into-tables/#findComment-511671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.