-1

I make a php page in which i populate csv file to the checkbox,how i count number of rows of csv file.

Here is my code:

$file = $fu['filepath'].$fu['filename'];
        $handle=@fopen($file,"r");
        if($handle) {
            while($row = fgetcsv($handle, 1024)){
echo "<input type='checkbox' name='receptionts[]' checked='checked' value='".$row[0].'|'.$row[1] ."' /> ".$row[0]." <br />";
                }
        } 
        else {
            // File doesn't exist. do something.
        }
Muhammad Arif
  • 1,014
  • 3
  • 22
  • 56

1 Answers1

3

Try the following:

$file = $fu['filepath'].$fu['filename'];
$fileData=@file($file,"r");
$noOfLines = count($fileData);        

if ($noOfLines > 0) {
    while ($row = fgetcsv($handle, 1024)) {
        echo "<input type='checkbox' name='receptionts[]' checked='checked' value='".$row[0].'|'.$row[1] ."' /> ".$row[0]." <br />";
    }
} else {
  // File doesn't exist. do something.
}

Hope this helps.

Denis Rendler
  • 193
  • 1
  • 1
  • 15