Solved

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

Posted on 2012-03-31
4
633 Views
Last Modified: 2012-03-31
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
Comment
Question by:dmalovich
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 37791866
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
 

Author Comment

by:dmalovich
ID: 37791921
It is http.  Do you have any other suggestions maybe?
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37791927
Close and re-open is your only choice I think.
0
 

Author Closing Comment

by:dmalovich
ID: 37791973
Yah I think so too, thanks......
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now