Jump to content

Omitting row from csv


acctman

Recommended Posts

I need help rewriting the $row_count... the problem is that its not working when the first row does not have quotations. its a strange problem, no errors it just does not process. Once I comment out the row_count the $data is outputted as normal. And when I process a file that has quotations it works. So i just need a better way of saying skip the first row in the $data output since thats the header.

 

$uploadcsv = "/files/004AM.csv";
     $handle = fopen($uploadcsv, 'r');
       $column_headers = array();
$row_count = 0;
while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
  if ($row_count==0){
    $column_headers = $data;
  } else {
    print_r($data);
  }
  ++$row_count;
}

Link to comment
https://forums.phpfreaks.com/topic/221242-omitting-row-from-csv/
Share on other sites

just an old man's ramblings...

$file_name = "/files/004AM.csv";
$lines = file($file_name);
if(count($lines)>1){
while($i=1; $i<=count($lines); $i ++) {
	echo $lines[$i] . "<br>";
}
}

 

thanks, how would I apply this to work with the fgetcsv coding that I'm currently using.

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.