|  | Posted by David Haynes on 05/30/06 15:49 
Patrick wrote:> I'm trying to while loop using a flat txt file and write the values out
 > into a form. I have 50-58 values to echo. Am I going to have to echo
 > each line of html. Or is there a way to make this work between the php.
 > Right now it wants to write the whole table over and over. Is my logic
 > screwed up? I am not a programmer as such but can get by. I have
 > something like this which is an abbreviated version. Any help would be
 > appreciated.
 >
 > Thanks,
 > Patrick
 
 If your input file looks something like this:
 fred, Barbados/123, Titanic
 sally, Turks/Caicos, Mary Celleste
 
 then the following code will help you get started:
 <html>
 <head>
 </head>
 <body>
 <?php
 $filename = "test.log";
 if( ! ($fd = fopen($filename, "r")) ) {
 echo "Cannot open $filename for read<br>\n";
 exit;
 }
 
 while( $line = fgets($fd, 80) ) {
 $values = explode(',', $line);	// assumes comma-separated values
 ?>
 
 <form method="post" action="precmlog.php">
 
 <table width="800" cellpadding="5" cellspacing="0" border="0">
 <tr>
 <td width="40%">
 Log sheet completed by:<br> <input class="inform" type="text"
 size="30" name="person" value="<?php echo $values[0]; ?>"><br>
 </td>
 </tr>
 <tr>
 <td>
 Cruise name/number:<br> <input class="inform" type="text"
 size="30" name="cruisenum" value="<?php echo $values[1]; ?>"><br>
 </td>
 </tr>
 
 <tr>
 <td>
 Ship name:<br> <input class="inform" type="text" size="30"
 name="shipname" value="<?php echo $values[2]; ?>"><br>
 </td>
 </tr>
 </table>
 
 <input class="button" type="submit"  value="Submit">
 </form>
 
 
 <?php
 }
 fclose($fd);
 ?>
 </body>
 </html>
 
 -david-
  Navigation: [Reply to this message] |