0

I've got my php working to count the number of rows in the full csv document, but trying to get a number of rows that have data in them in a particular column. Is this possible with PHP?

$fp = file('test.csv');
echo count($fp);
2
  • 1
    It's possible! How are you counting rows? Please edit your post to include code snippets that are appropriate. Commented May 7, 2015 at 13:45
  • yes I tried counting columns and other approaches but can't seem to figure it out. Commented May 7, 2015 at 13:56

1 Answer 1

3

You can use fgetcsv function and check in every row the data.

For example if you want to check how many rows have data in the second column, run that.

$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
  if ($data[1] != '')
  {
    // check the data specifically in the second column
    $data_found ++;
  }
}
echo 'Rows with data in the second column:'.$data_found;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.