Jump to content

Need to be able to write a column to a flat text file and also to display ...


husslela03

Recommended Posts

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);

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>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.