• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

Not getting data when trying to use fgetcsv() twice.

I've opened up a csv file using:

$fp = @fopen ("myfile.csv","r");

if($fp){

$lastrow;

while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {      
      
      //get first day of data
     $lastrow = $data;
}

//cycle through again using lastrow as input
while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {      
      
  //use last row as input

}



I cycle through the csv file and get the last row using the above code.  I want to cycle through the csv file again using the last row as input to extract other data.

I've tried using fseek to reset the pointer to the beginning of the file but I get this error message:  Warning: fseek() [function.fseek]: stream does not support seeking in




How can I cycle through the csv file twice?
0
dmalovich
Asked:
dmalovich
  • 2
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
You can use rewind() http://us2.php.net/manual/en/function.rewind.php as long as it is a local file.  If it's 'http' or 'ftp', it doesn't work.
0
 
dmalovichAuthor Commented:
It is http.  Do you have any other suggestions maybe?
0
 
Dave BaldwinFixer of ProblemsCommented:
Close and re-open is your only choice I think.
0
 
dmalovichAuthor Commented:
Yah I think so too, thanks......
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now