Reading multiple Excel Lines

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
acschnabel
Forum Newbie
Posts: 1
Joined: Tue Apr 26, 2011 3:38 pm

Reading multiple Excel Lines

Post by acschnabel »

I have a php file that downloads a csv file from an external website. It prints the first line of the file (header) into a table, then searches through the file for a string match, and prints the line that the match appears on. So essentially, I end up with a 2 row table with a header row and the data I'm looking for.

Code: Select all

    $fp = fopen($fullFileName,'r') or die("can't open file");
    print "<table>\n";

    while($csv_line = fgetcsv($fp,1024)) {
       if($csv_line[1] == "Target") {
                print '<tr>';
           for ($i = 1, $j = count($csv_line); $i < $j; $i++) {
               print '<td>'.$csv_line[$i].'</td>';
           }
           print "</tr>\n";
       }
       if ($csv_line[3] == $bandwidthTime) {
             
          print '<tr>';
           for ($i = 1, $j = count($csv_line); $i < $j; $i++) {
               print '<td>'.$csv_line[$i].'</td>';
           }
           print "</tr>\n";
       }
    }
    print '</table>';
Now what I need to get is the current row that is being printed and the previous 20 rows in the excel sheet. I'm assuming I need a for loop, however, I don't know how to get the current row that the data was located on.

Thanks in advance for your help.
Tony.
Post Reply